Linux – How to set the password of a new user after the account has already been created

linuxpassworduseradd

I used the 'useradd' command to create a new account, but I did so without specifying the password. Now, when the user tries to log in, it asks him for a password. If I didn't set it up initially, how do I set the password now?

Best Answer

Easiest way to do this from the command line is to use the passwd command with root privileges.

passwd username

From man 1 passwd

NAME
       passwd - update user's authentication token
SYNOPSIS
       passwd  [-k]  [-l]  [-u [-f]] [-d] [-n mindays] [-x maxdays]
       [-w warndays] [-i inactivedays] [-S] [--stdin] [username]
DESCRIPTION
       The passwd utility is used to update user's authentication token(s).

After you set the user password, you can force the user to change it on next login using the chage command (also with root privileges) which expires the password.

chage -d 0 username

When the user successfully authenticates with the password you set, the user will automatically be prompted to change it. After a successful password change, the user will be disconnected, forcing re-authentication with the new password.

See man 1 chage for more information on password expiry.

Related Question