Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

preface

As the question, I believe that many new to Ubuntu system will encounter this problem, so how do we solve this problem? Ubuntu does not ask us to set a root password during the installation process, but it does ask us to enter the root password when we need to obtain root permissions, as shown below.This is where we get confused. When we installed the system, we only set a user name and password, and did not set the password of root user. You might enter the password of the user you created in the spirit of giving it a try, but of course the password is wrong!!

The cause of the error?

Before the password is set, the default root password in Ubuntu is random, that is, a new root password will be generated every time you boot up. Therefore, the password of the root user is uncertain.

How to solve it?

Open the terminal in Ubuntu (CTRL + Alt + T), type sudo passwd as shown in the image below, and repeat the root password twice to prompt you that the password has been updated.

  • Test whether the setting is successful: enter in the consolesu root, and then enter the root password to test whether the change is successful. The following figure shows the successful change.

Example Change the password of a specified user

  • First you need to switch torootUser: Entersudo suAnd then enter the password of user root to switch torootUsers;

  • Then enterPasswd username, enter the new password to be changed and repeat twice. At this time, it will return to the message indicating that the user authentication token has been updated successfully.