To add or change a password for a user in Linux, you can use the
passwd command followed by a space and the
username in Linux.
For example, let's say you want to add or change the password of the user
john, you can use the
passwd command like this,
# Add or change the password for a user
sudo passwd john
- This will show you a prompt where you can set or change the password for the user, in our case
- Sometimes you may need to use the
sudocommand before the
passwdcommand to obtain the correct privileges to execute the command.
Try executing the above command in this online terminal to see the result.