V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wdssmq
V2EX  ›  分享发现

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

  •  
  •   wdssmq · 2022-05-24 20:34:06 +08:00 · 1239 次点击
    这是一个创建于 910 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    1 条回复    2022-05-24 23:44:42 +08:00
    cxxlxx
        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.

    按照这个
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3340 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 11:22 · PVG 19:22 · LAX 03:22 · JFK 06:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.