安装好WSL后,默认的用为自己设置的,每次执行命令都要sodu以下,毕竟是自己开发环境用的,没必要这么麻烦,索性直接改默认用户为root,这里以Ubuntu为例:

首先以管理员身份打开cmd命令行,查看用法:

C:\WINDOWS\system32> ubuntu /?
Launches or configures a Linux distribution.

Usage:
    <no args>
        Launches the user's default shell in the user's home directory.

    install [--root]
        Install the distribuiton and do not launch the shell when complete.
          --root
              Do not create a user account and leave the default user set to root.

    run <command line>
        Run the provided command line in the current working directory. If no
        command line is provided, the default shell is launched.

    config [setting [value]]
        Configure settings for this distribution.
        Settings:
          --default-user <username>
              Sets the default user to <username>. This must be an existing user.

    help
        Print usage information.

根据提示,接下来:

ubuntu config --default-user root

再次打开wsl是不是就默认以root进来了呢,如果没有,就重启一下wsl服务:

net stop LxssManager
net start LxssManager

当然你可以在服务里找到LxssManager服务,右键重启。