AlexiaChen / AlexiaChen.github.io

My Blog https://github.com/AlexiaChen/AlexiaChen.github.io/issues
87 stars 11 forks source link

WSL用了export再import导入到一个特定目录无法指定Linux默认用户的问题 #102

Open AlexiaChen opened 4 years ago

AlexiaChen commented 4 years ago

如果没有经过标题的操作,运行以下命令就可以了:

<DistroName> config --set-default-user [username] 

但是,经过导出导入后,默认登陆进去是root用户,我想换回来我自己的用户。发现以上方法不行了。

还好找到了WSL官方的这个issue

步骤:

 Function WSL-SetDefaultUser ($distro, $user) { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); };
 WSL-SetDefaultUser <DistroName> <username>

这个方法比较麻烦,发现还操作注册表了,对用户暴露了过多细节,这只是临时方案,希望微软以后改进。比如这样:

wsl <DistroName> --set-default-user <username>
owenstake commented 2 years ago

现在还是有这个问题,我只能每次重启后 输入 Ubuntu2004 config --default-user <username>

AlexiaChen commented 2 years ago

现在还是有这个问题,我只能每次重启后 输入 Ubuntu2004 config --default-user <username>

你不看我的解决办法吗?

AlexiaChen commented 2 years ago

要写一个powershell的函数,这样你就不需要每次这样了。好好看内容吧。@owenstake