Article directory
After installing an ubuntu virtual machine on VMware, what is the password for the root user? During the installation process, there is no prompt for the password of the root user, only the password of the first non-root user is created. But the root user exists, so how to switch to the root user?
In fact, the root user exists, but does not have a password. If you enter the command su root
and then enter the password to create the first account, the following error will be prompted:
su: Authentication failure
The root password was not entered during the installation process. Is there a way to create a root password, or to enter the root user through other means? It’s all there! Below are introduced one by one.
Enter the root account
Let’s first talk about how to enter root, enter the following command.
Note: H
It’s in capital letters!
sudo -sH
After pressing Enter, you can see that the system prompts me to enter the user password for the first account I created. After pressing Enter, I can see that I have switched to the root user.
Even if a root password is set, you can use this method to switch to the root user.
Note that not all users can use the command to switch to the root user. As shown below, when using this command on a normal user ubuntu, the switch fails. According to the prompt, the ubuntu user is not in the sudoers file. The path of this file is: /etc/sudoers.
This file requires an administrator to view it. Switch to the root account and enter the following command to view it.
cat /etc/sudoers
I don’t seem to see the first created account. Does the first created account have any privileges?
Set root password
If you want to set an independent root password, you can enter the following command and press Enter.
sudo passwd
Enter new UNIX password:
Enter the newly set root password later, and then Retype new UNIX password:
enter the password again. If the two inputs are consistent, the modification will be successful.
This works even if you enter this command on the first account.
After the setting is successful, you can directly use the following command plus the root independent password to log in to the root user.
su root
summary
To switch the root account without setting a password (only the first account), use the following command and enter the password of the first account as prompted. (You can also use this method if you have set a password)
sudo -sH
To switch the root account with a password set, use the following command and enter the root password as prompted.
su root
To set or modify the root account password, use the following command
sudo passwd