Merge pull request #22387 from geekpi/translating

translated
This commit is contained in:
geekpi 2021-07-01 08:49:42 +08:00 committed by GitHub
commit 93b9f3fef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 139 additions and 139 deletions

View File

@ -1,139 +0,0 @@
[#]: subject: (Forgot Linux Password on WSL? Heres How to Reset it Easily)
[#]: via: (https://itsfoss.com/reset-linux-password-wsl/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
Forgot Linux Password on WSL? Heres How to Reset it Easily
======
WSL (Windows Subsystem for Linux) is a handy tool for people who want to enjoy the power of Linux command line from the comfort of Windows.
When you [install Linux using WSL on Windows][1], you are asked to create a username and password. This user is automatically logged on when you start Linux on WSL.
Now, the problem is that if you havent used it for some time, you may forget the account password of WSL. And this will become a problem if you have to use a command with sudo because here youll need to enter the password.
![][2]
Dont worry. You can easily reset it.
### Reset forgotten password for Ubuntu or any other Linux distribution on WSL
To reset the Linux password in WSL, you have to:
* Switch the default user to root
* Reset the password for the normal user
* Switch back the default user to the normal user
Let me show you the steps in detail and with screenshots.
#### Step 1: Switch to root as default user
It will be wise to note down your accounts normal/regular username. As you can see, my regular accounts username is abhishek.
![Note down the account username][3]
The root user in WSL is unlocked and doesnt have a password set. This means that you can switch to the root user and then use the power of root to reset the password.
Since you dont remember the account password, switching to the root user is done by changing the configuration of your Linux WSL application and make it use root user by default.
This is done through Windows Command Prompt and youll need to know which command you need to run for your Linux distribution.
This information is usually provided in the description of the distribution app in the [Windows Store][4]. This is from where you had downloaded your distribution in the first place.
![Know the command to run for your distribution app][5]
From the Windows menu, start the command prompt:
![Start Command Prompt][6]
In here, use your distributions command in this fashion. If you were using the Ubuntu app from Windows store, the command would be:
```
ubuntu config --default-user root
```
In the screenshot, I am using Ubuntu 20.04 app from the Windows store. So, I have used ubuntu2004 command.
![Set root as default user in Linux apps configuration][7]
To save you the trouble, I am listing some distributions and their respective commands in this table:
Distribution App | Windows Command
---|---
Ubuntu | ubuntu config default-user root
Ubuntu 20.04 | ubuntu2004 config default-user root
Ubuntu 18.04 | ubuntu1804 config default-user root
Debian | debian config default-user root
Kali Linux | kali config default-user root
#### Step 2: Reset the password for the account
Now, if you start the Linux distribution app, you should be logged in as root. You can reset the password for the normal user account.
Do you remember the username in WSL? If not, you can always check the contents of the /home directory. When you have the username, use this command:
```
passwd username
```
It will ask you to enter a new password. **When you type here, nothing will be displayed on the screen. Thats normal. Just type the new password and hit enter.** Youll have to retype the new password to confirm and once again, nothing will be displayed on the screen while you type the password.
![Reset the password for the regular user][8]
Congratulations. The password for the user account has been reset. But you are done just yet. The default user is still root. You should change it back to your regular account user, otherwise it will keep on logging in as root user.
#### Step 3: Set regular user as default again
Youll need the regular account username that you used with the [passwd command][9] in the previous step.
Start the Windows command prompt once again. **Use your distributions command** in the similar manner you did in the step 1. However, this time, replace root with the regular user.
```
ubuntu config --default-user username
```
![Set regular user as default user][10]
Now when you start your Linux distribution app in WSL, youll be logged in as the regular user. You have reset the password fresh and can use it to run commands with sudo.
If you forgot the password again in the future, you know the steps to reset it.
### If resetting WSL password is this easy, is this not a security risk?
Not really. You need to have physical access to the computer along with access to the Windows account. If someone already has this much access, she/he can do a lot more than just changing the Linux password in WSL.
### Were you able to reset WSL password?
I gave you the commands and explained the steps. I hope this was helpful to you and you were able to reset the password of your Linux distribution in WSL.
If you are still facing issues or if you have a question on this topic, please feel free to ask in the comment section.
--------------------------------------------------------------------------------
via: https://itsfoss.com/reset-linux-password-wsl/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/install-bash-on-windows/
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/reset-wsl-password.png?resize=800%2C450&ssl=1
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/username-wsl.png?resize=800%2C296&ssl=1
[4]: https://www.microsoft.com/en-us/store/apps/windows
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/wsl-distro-command.png?resize=800%2C602&ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/start-cmd-windows.jpg?resize=800%2C500&ssl=1
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/wsl-set-root-as-default.png?resize=800%2C288&ssl=1
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/resetting-wsl-password.png?resize=800%2C366&ssl=1
[9]: https://linuxhandbook.com/passwd-command/
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/set-regular-user-as-default-wsl.png?resize=800%2C288&ssl=1

View File

@ -0,0 +1,139 @@
[#]: subject: (Forgot Linux Password on WSL? Heres How to Reset it Easily)
[#]: via: (https://itsfoss.com/reset-linux-password-wsl/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
在 WSL 上忘记了 Linux 密码?下面是如何轻松重设的方法
======
对于那些想从舒适的 Windows 中享受 Linux 命令行的人来说WSLWindows Subsystem for Linux 是一个方便的工具。
当你[在 Windows 上使用 WSL 安装 Linux][1]时,会要求你创建一个用户名和密码。当你在 WSL 上启动 Linux 时,这个用户会自动登录。
现在的问题是,如果你有一段时间没有使用它,你可能会忘记 WSL 的账户密码。而如果你要使用 sudo 的命令,这将成为一个问题,因为这里你需要输入密码。
![][2]
不要担心。你可以很容易地重置它。
### 在 Ubuntu 或任何其他 Linux 发行版上重置遗忘的 WSL 密码
要在 WSL 中重设 Linux 密码,你需要:
* 将默认用户切换为 root
* 重置普通用户的密码
* 将默认用户切换回正常用户
让我向你展示详细的步骤和截图。
#### 步骤 1将默认用户切换为 root
记下你的普通/常规用户名将是明智之举。如你所见,我的普通帐户的用户名是 abhishek。
![Note down the account username][3]
WSL 中的 root 用户是解锁的,没有设置密码。这意味着你可以切换到 root 用户,然后利用 root 的能力来重置密码。
由于你不记得帐户密码,切换到根用户是通过改变你的 Linux WSL 应用的配置,使其默认使用 root 用户来完成。
这是通过 Windows 命令提示符完成的,你需要知道你的 Linux 发行版需要运行哪个命令。
这个信息通常在 [Windows Store][4] 中的发行版应用的描述中提供。这是你首次下载发行版的地方。
![Know the command to run for your distribution app][5]
从 Windows 菜单中,启动命令提示符:
![Start Command Prompt][6]
在这里,以这种方式使用你的发行版的命令。如果你使用的是 Windows 商店中的 Ubuntu 应用,那么该命令将是:
```
ubuntu config --default-user root
```
截图中,我正在使用 Windows 商店中的 Ubuntu 20.04 应用。所以,我使用了 ubuntu2004 命令。
![Set root as default user in Linux apps configuration][7]
为了减少你的麻烦,我在这个表格中列出了一些发行版和它们各自的命令:
发行版应用 | Windows 命令
---|---
Ubuntu | ubuntu config default-user root
Ubuntu 20.04 | ubuntu2004 config default-user root
Ubuntu 18.04 | ubuntu1804 config default-user root
Debian | debian config default-user root
Kali Linux | kali config default-user root
#### 步骤 2重设帐户密码
现在,如果你启动 Linux 发行程序,你应该以 root 身份登录。你可以重新设置普通用户帐户的密码。
你还记得 WSL 中的用户名吗?如果没有,你可以随时检查 /home 目录的内容。当你有了用户名后,使用这个命令:
```
passwd username
```
它将要求你输入一个新的密码。**当你输入时,屏幕上将不会显示任何内容。这很正常。只要输入新的密码,然后点击回车就可以了。**你必须重新输入新的密码来确认,当你输入密码时,屏幕上也不会显示任何东西。
![Reset the password for the regular user][8]
恭喜你。用户账户的密码已经被重置。但你还没有完成。默认用户仍然是 root。你应该把它改回你的普通用户帐户否则它将一直以 root 用户的身份登录。
#### 步骤 3再次将普通用户设置为默认用户
你需要你在上一步中用 [passwd 命令][9]使用的普通帐户用户名。
再次启动 Windows 命令提示符。**使用你的发行版命令**,方式与第 1 步中类似。然而,这一次,用普通用户代替 root。
```
ubuntu config --default-user username
```
![Set regular user as default user][10]
现在,当你在 WSL 中启动你的 Linux 发行版时,你将以普通用户的身份登录。你已经重新设置了密码,可以用它来运行 sudo 的命令。
如果你将来再次忘记了密码,你知道重置密码的步骤。
### 如果重设 WSL 密码如此简单,这难道不是一种安全风险吗?
并非如此。你需要有对计算机的物理访问权以及对 Windows 帐户的访问权。如果有人已经有这么多的访问权,他/她可以做很多事情,而不仅仅是改变 WSL 中的 Linux 密码。
### 你是否能够重新设置 WSL 密码?
我给了你命令并解释了步骤。我希望这对你有帮助,并能够在 WSL 中重置你的 Linux 发行版的密码。
如果你仍然遇到问题,或者你对这个话题有疑问,请随时在评论区提问。
--------------------------------------------------------------------------------
via: https://itsfoss.com/reset-linux-password-wsl/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/install-bash-on-windows/
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/reset-wsl-password.png?resize=800%2C450&ssl=1
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/username-wsl.png?resize=800%2C296&ssl=1
[4]: https://www.microsoft.com/en-us/store/apps/windows
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/wsl-distro-command.png?resize=800%2C602&ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/start-cmd-windows.jpg?resize=800%2C500&ssl=1
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/wsl-set-root-as-default.png?resize=800%2C288&ssl=1
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/06/resetting-wsl-password.png?resize=800%2C366&ssl=1
[9]: https://linuxhandbook.com/passwd-command/
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/set-regular-user-as-default-wsl.png?resize=800%2C288&ssl=1