Bash/WSL - 如何以 root 身份 运行 命令?
Bash/WSL - How to run command as root?
>ubuntu1804.exe -c "echo $USER"
mpen
那个 运行 作为我的命令,我如何 运行 它作为 root?
帮助页面甚至没有提到 -c
>ubuntu1804.exe help
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.
原来还有另一个简单地称为 wsl
的命令,它允许您 运行 作为任意用户的任意命令:
>wsl -u root -d Ubuntu-18.04 -- echo "I am g$USER"
I am groot
N.B。您需要为此使用单独的参数(而不是字符串)。
-d
是可选的。您可以更改默认发行版
wslconfig.exe /l
wslconfig.exe /s Ubuntu-18.04
wslconfig.exe /l
wslconfig /l
似乎等同于 wsl --list
如果您需要运行多个命令,只需以root身份登录:
wsl -u root
和运行所有命令交互
>ubuntu1804.exe -c "echo $USER"
mpen
那个 运行 作为我的命令,我如何 运行 它作为 root?
帮助页面甚至没有提到 -c
>ubuntu1804.exe help
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.
原来还有另一个简单地称为 wsl
的命令,它允许您 运行 作为任意用户的任意命令:
>wsl -u root -d Ubuntu-18.04 -- echo "I am g$USER"
I am groot
N.B。您需要为此使用单独的参数(而不是字符串)。
-d
是可选的。您可以更改默认发行版
wslconfig.exe /l
wslconfig.exe /s Ubuntu-18.04
wslconfig.exe /l
wslconfig /l
似乎等同于 wsl --list
如果您需要运行多个命令,只需以root身份登录:
wsl -u root
和运行所有命令交互