从文件导入的 wsl 发行版如何更改默认用户

2022-05-24 20:34:06 +08:00
 wdssmq

从应用商店安装时创建了用户,导入后则默认是 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

https://stackoverflow.com/questions/61474401/how-to-change-the-default-user-after-import-old-wsl-tar-package

Set Default User for Windows Subsystem for Linux Distro in Windows 10 | Tutorials

https://www.tenforums.com/tutorials/128152-set-default-user-windows-subsystem-linux-distro-windows-10-a.html

1065 次点击
所在节点    分享发现
1 条回复
cxxlxx
2022-05-24 23:44:42 +08:00
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.

按照这个

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/855056

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX