WSL:登陆指定Linux子系统(在安装了多个Linux子系统的情况下)

avatar
作者
筋斗云
阅读量:2

To login you need to run:

wsl -d <Distribution Name> 

Step 5: Setup user accounts

Notice in the above image that the logged in user is a root account. So let's setup a normal user account.

First, while logged in to the second instance of Ubuntu in WSL2 as root, run the below command, replace <USERNAME> with the username of your choice:

NEW_USER=<USERNAME> 

Then, run the following command to create the user account and set the password:

useradd -m -G sudo -s /bin/bash "$NEW_USER" passwd "$NEW_USER" 

Step 6: Configure default user

Next, we need to configure Ubuntu to log in as your new user by default instead of root.

To do so, run the below command: paste the entire block of code below into your teminal and press enter.

tee /etc/wsl.conf <<_EOF [user] default=${NEW_USER} _EOF 

Step 7: Login as the new user

First, exit the WSL by running logout, then shutfown the second Ubuntu by running

wsl --terminate <Distribution Name> 

Finally, login to the second instance of Ubuntu again:

wsl -d <Distribution Name> 

Need Help? Open a discussion thread on GitHub.

How to install multiple instances of Ubuntu in WSL2

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!