You can use the passwd command to change your password, and, as a system administrator, change the password of the root account, or another user in your Linux system. The syntax is as follows:
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | passwd command |
Time | Less than a minute |
OR
passwd {userName}
OR
passwd [option] userNameHere
Task: Linux Change Your Own Password
Login using the ssh client or open a command-line terminal (select Applications > Accessories > Terminal), than type the following command:
$ passwd
First, the user is prompted for their current password. If the current password is correctly typed, a new password is requested. The new password must be entered twice to avoid typing errors. Running passwd command with no arguments will allow you to change your own password.
Task: Linux Change root’s User Password
To change root’s password, you must first login as root user or use sudo / su command to obtain root’s credentials. To become the root user, enter:
$ su -l
OR
$ sudo -s
To change root’s password, enter:
# passwd
Task: Linux Change Another User’s Password
To change the password of another user, login as root and type:
# passwd userNameHere
# passwd tom
# passwd jerry
A note about protecting your password
Your password unlocks your account and all data on Linux. So you need to protect your password. Here are some simple tips:
- Please do not write down your password. You need to memorize it.
- Do not use the same password for all your accounts including ssh, git, file and email servers. Use unrelated passwords for systems controlled by different organizations.
- Do not share or give your password, in particular to some one claiming to be from computer IT support department or a vendor.
- Make sure no one watch you enter your password.
- Change password periodically.
- Choose a hard-to-guess password. Avoid using the following passwords:
- Simple words or words that you’d find in a dictionary.
- Do not use your name including that of a spouse, child, pet, city and so on.
- Do not use your birhdate, ssn/pan, phone/mobile number and driving license numbers.
- A good password consists of:
- Mixture of upper and lower case letters, as well as digits or punctuation.
- At least 8 characters long.
Password example
- Passphrase : I love Pizza and Beer.
- Take the first letter of each word in a passphrase – I l P a B
- Add digits: I2 l P a9B
- Add special character: I2+l P&a9B
- Add other characters: qI2+lUP&a9Bw
See how to generate a random password using the shell and/or mkpasswd command.
Storing password securely
Use personal password manager to store all passwords in a securely encrypted file. I recommend:
- gpass application.
- See a list of 7 apps that works under OS X/Linux and MS-Windows to store passwords.
Getting Help
Anytime you need assistance with Linux passwd command-line, turn to the man page first. It will give you detailed information, parameters and switches for passwd command. For example, man passwd opens the man page for the passwd command:
$ man passwd
$ man 5 passwd
See also
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 9 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
1. Switch to root
[user1@localhost ~]$ su –
Password:
2. Change password for user2
[root@localhost ~]# passwd user2
Changing password for user user2.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#
wat can chang passward of root
he can chang passwad of root
[root@localhost ~]# useradd speed
[root@localhost ~]# passwd speed < rambabu
> rambabu
> EOF
Changing password for user speed.
New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password: passwd: all authentication tokens updated successfully.
[root@localhost ~]# useradd abcde
[root@localhost ~]# echo “password” | passwd –stdin abcde
Changing password for user abcde.
passwd: all authentication tokens updated successfully.
Hello ! i want to ask how i can change password for root if i forget my root pass and my linux is also need a login password . i forget login password for my user name ******* .how i can login to my workspace .
Login in single user mode and change the password. When you start the system just press the Ctrl+x for login in single user mode. And you will login there as root without password and you can change there your root password.
booting the machine, at that time press “a” then click the space bar and type “s” then click enter first we check if it is enforcing mode or permissive mode by using this “getenforce” command if it is “enforcing” setenforce 0 then it will be change permissive mode . then “passwd –stdin root” type the password that’s it…………
How about changing user I D and password not knowing either? Who am I requesting this info. from? Thanks ldn
If you are sudo-user you can also change your root password, without logging in into root:
> sudo su
> passwd
For the “issue”: BAD PASSWORD: it is based on a dictionary word
Try this: (you should be ROOT)
cd /etc/pam.d
vi system-auth
Comment all the three lines
Add this line
Make sure that you keep a login session open and test from another session.
This way you will not lock yourself out.
Good luck!
On RHEL66 it works.
Nick.