Useful Tips

How to change root password in Ubuntu


in the terminal - sudo passwd root

Change password without terminal

Click the rightmost icon on the menu bar and select System Settings.

Open Accounts.

Click the label next to Password.

This plate looks like a series of dots or squares if the password already exists.

Enter a valid password and then a new password. Enter the new password again in the Confirm password field.

Root password change

Ubuntu uses a command to change passwords passwd. You need to open the terminal and log in to the root user in it:

The shell, at the same time, will ask you to enter the administrator password. After successfully entering the password, a root prompt will appear.

Now you can perform the password change procedure directly:

After entering this command, you will be prompted to enter a new sudo password twice (to exclude typos).

When the password is successfully changed, you can go back to the normal user shell with the command:

Now when using the sudo command, you can use the new password - it has been changed.

Change password for any user

In order to use this command (passwd) to change the password not of your (active) account, but of another you need to use the extended syntax:

Of course, the command in this case should be executed through sudo. After entering such a design, it will also be proposed to enter a new password twice, only for the user argument specified.

How to change user password

You can change your password whenever you want. To do this, you do not need special superuser rights, only know your current password. Just open a terminal and run the utility passwd without parameters:

Next, you need to enter a new password - and you're done, now it's changed. It is encoded using irreversible encryption and stored in the / etc / shadow file. But note that you cannot use any password here. The Linux system ensures that users select fairly complex passwords. If it is very short or contains only numbers, you cannot install it.

General requirements for the password are as follows: must contain from 6 to 8 characters, and one or more of them must belong to at least two of the following sets:

  • Lower case letters
  • Uppercase letters
  • Numbers from zero to nine
  • Punctuation and _

Now let's look at how to change the Linux password for another user.

How to change the password of another user

Everything is clear with your password, but if you want to change the code for another user, you will have to exercise superuser rights. And the rest of the process is the same:

sudo passwd user

Here user is a user who needs a Linux password change. The password requirements are the same: you cannot set a password that is too simple.

You can remove the Linux password for the user, then he will not be able to log in:

sudo passwd -d user

How to change a group password

You probably saw the file / etc / gshadow on your system. This file is equivalent to / etc / shadow, only contain passwords for groups. You cannot log in on behalf of a group, but, knowing its password, you can access the functions it provides in a separate command shell using the command newgrp.

To set a password for a group, a utility is used that is very similar to passwd - gpasswd. Naturally, we need superuser rights. For example:

sudo gpasswd disk

Now let's try to get group permissions:

After entering the password, we temporarily end up in this group and can work with those files to which this group is allowed access. To remove a Linux password from a group, use the option -r:

sudo gpasswd -r disk

How to force the user to change the password

Server security is one of the most important things. Often the cause of security problems is users themselves who do not change passwords often or make them too simple. If you are an administrator, you have the opportunity to force users to change their password from time to time, and also automatically send them alerts that it is time to change the Linux user password.

All this allows the utility to do passwd. First, let's look at how to view password information in passwd. To do this, use the option -S:

  • The first field is the username
  • The second field shows one of the values: P - password is set, L - the user is blocked, NP - no password.
  • 07/21/2016 - date of the last password change.
  • 0 - minimum time before password change
  • 99999 - maximum password duration
  • 7 - for how many days you need to warn about the expiration of the password
  • -1 - after how many days the password needs to be deactivated.

For example, thirty days after the change, the user's password will become obsolete:

sudo passwd -x 30 test

Three days before the password expires, we warn the user that it needs to be changed:

sudo passwd -w 3 test

If he does not do this within five days, the account must be disabled:

sudo passwd -i 3 test

The password can be changed no more than once every 10 days:

sudo passwd -n 10 test

We look now at what happened:

sudo passwd -S test

How to change root password

Changing the Linux password for root is very simple, just like for any other user. Only need to have superuser privileges. This is how it will look:

sudo passwd root

Everything is working. In the same way, you can set the root password in Ubuntu.

How to manually change the password

The Linux operating system would not be Linux if we were not able to configure the password manually without any utilities. As I said before, passwords are stored in the / etc / shadow file. And they are stored there in encrypted form. It is not possible to decrypt the password.

When the system saves the password, it performs encryption according to a certain algorithm and saves the encrypted result, and when the user needs to log into the system, it simply takes its password, again encrypts and verifies that it is stored in / etc / shadow. If it matches, the user is authorized.

Even in this way, changing the Linux user password is not so difficult. So, first we need to get the encrypted password. This can be done in several ways, for example using openssl:

openssl passwd -1 -salt xyz yourpass

Replace xyz for any random combination of characters, the more the better yourpass - this is your new password.

Copy the result to the clipboard, then open the / etc / shadow file and find the user there. I want to change the Linux password for test:

sudo vi / etc / shadow

The syntax for this file is:

Username: Password: .

The next field indicates the last password change in the form of the number of days that have passed since January 1, 1970. The rest of the fields do not interest us, and you can figure it out very simply by comparing the data.

Now replace the password with the one received above and saved to the clipboard. Save the file and you can try to log in with a new password:

Everything is working. As I said, there are several more encryption algorithms with which you can get a password, here they are:

makepasswd --clearfrom = - --crypt-md5

In all of these examples salt is a random string to increase the strength of encryption, and Yourpass - your password. What to do with the received data you already know.

In this article, you learned how to change your Linux password. I considered all possible ways and not even very standard ones. If you still have questions, write comments!