从应用商店安装时创建了用户,导入后则默认是 root 用户,想切换回去;
# 从文件导入
wsl --import Ubuntu "C:\wsl\Ubuntu" "D:\#bak\WSL\wsl-2022-05-24.tar"
# 查看列表
wslconfig /l
# Ubuntu-18.04 (默认)
# Ubuntu
# 可以执行,但是好像没效果
ubuntu1804 config --default-user wdssmq
# 也试过切换默认后执行上边命令
wslconfig /setdefault Ubuntu
# 会提示不存在
# ubuntu config --default-user wdssmq
最后尝试停用其他的项只留要修改的好像就可以了?
wsl -l -v
# NAME STATE VERSION
#* Ubuntu Running 2
# Ubuntu-18.04 Running 2
# wsl --shutdown
wsl -t Ubuntu-18.04
wsl -l -v
# NAME STATE VERSION
#* Ubuntu Running 2
# Ubuntu-18.04 Stopped 2
ubuntu1804 config --default-user wdssmq
严格来说不清楚生效的是哪个方案,因为我同时设置了/etc/wsl.conf
:
[在 wsl 发行版内部]
[user]
default=wdssmq
windows subsystem for linux - Change default WSL 2 user after export/import - Super User
https://superuser.com/questions/1602502/change-default-wsl-2-user-after-export-import
windows subsystem for linux - how to change the default user after import old wsl tar package? - Stack Overflow
Set Default User for Windows Subsystem for Linux Distro in Windows 10 | Tutorials
1
cxxlxx 2022-05-24 23:44:42 +08:00 1
Note this new restored distribution will login as root so you need to change the registry key to the default UUID of 1000.
First open the registry by hittingWindows Button + R, then type in regedit and hit return. This should open up the registry. Next move to the folder `aHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss` Now look down the list of registry entries in there and see which one matches the name you gave your distribution. Then go to the DefaultUid and change this to decimal 1000 not hexidecimal as this will not work. Next time you launch your restored WSL setup it should start normally with your usual setup rather than as root. 按照这个 |