The computer is equipped with dual systems, but I have used the server for several months, and I have not used another system (Ubuntu20.04) on the local computer. I accidentally selected Ubuntu when I turned it on, but I forgot the login password.
Article directory
1. Modify the login password
Use the following steps to reset your password:
-
Restart your computer. While GRUB is loading a page, press
Shift
the key to display the GRUB menu. If your computer is dual system, the GRUB menu should be displayed automatically. -
In the GRUB menu, select
Advanced options for Ubuntu
, and pressEnter
the key.
-
In the next menu, select
Recovery mode
and pressEnter
the key.
-
In the next menu, select
root
and pressEnter
the key. This will boot your system in root mode.
-
You should now see a command line prompt. First, you need to remount your filesystem for read and write operations. You can do this with the following command:
mount -o remount,rw /
-
Next, you can use
passwd
the command to change the user password. For example, if your username isusername
, you can use the following command to change the password:passwd username
Please
username
replace with your actual username. -
You will be prompted to enter a new password. After entering your new password twice, your password will be changed.
-
Finally, restart your computer with the following command:
reboot
If you can’t remember the user name, it doesn’t matter. Enter /home
the directory, and you can usually see the directory named after the user name:
2. Delete/unlock the keyring
Because the login password has been modified, it will display after entering the system: The secret used to log in to the computer no longer matches the password in the key ring
Keyring is a security feature used to store and protect various passwords, such as browsers, SSH, GPG, etc.
You need to enter your previous password to unlock, otherwise this page will pop up from time to time.
Delete the keyring file if you can't remember the old password.
-
Open Applications - Tools - Passwords and Keys
-
Switch to the Passwords tab and you'll see a password keyring (mine is login).
-
Right click and delete.
If the server forgets the password : go to the console of the server manufacturer to modify it.
Three, Linux system root user password problem
In Ubuntu and many other Linux distributions, the root user has no password by default . This is for security reasons. On these systems, when you need to execute a command that requires root privileges, you usually use the sudo command and enter your user password. The advantage of this is that even if the attacker knows that the root user exists, they cannot log in directly with the root user because the root user does not have a password.
However, you can choose to set a password for the root user, although this is generally not recommended. If you choose to do this, you need to make sure your root password is strong enough, and only use root when necessary.
In case you forget your username and password, you can get a root shell in recovery mode, then view the username and reset the password. This is because in recovery mode, the system boots in single-user mode, which means that the system automatically logs in as root without requiring a password.
This is an important reason why I can change the login password.
In a server environment, the root user usually has a password because the server needs to be managed remotely, and remote management usually requires root privileges. In this case, the root user needs to have a password so that the administrator can log in via remote access tools such as SSH. (On the other hand, many server manufacturers use root as the default login user, Tencent Cloud does not seem to be)
However, using the root user directly is not recommended, even in a server environment. The usual practice is to create a normal user with sudo privileges, and then use this user for daily management. Use the sudo command to temporarily elevate privileges only when you need to perform specific root-privilege operations.
Additionally, many modern Linux distributions, including Ubuntu, support authentication using SSH key pairs instead of passwords. This method is more secure because even if an attacker knows the username, they cannot log in without the private key.
In summary, direct use of the root user is not recommended, whether in a desktop environment or in a server environment. Regular users and the sudo command should be used whenever possible to reduce security risks.
Write love you forever into the end of the poem ~