The steps to change a password on Linux can be simple—or they can be quite tricky. It all depends on details of your situation. But whether you just need to change a password in GNOME or you need to reset the password from Linux’s emergency command line, you’ll find all of the steps in this article.
Linux is based on Unix, an operating system almost old enough to qualify for Social Security. Computer security wasn’t such a big deal back when computers cost millions of dollars and sat in secure rooms, so Unix was written to let all users see each others’ encrypted passwords.
The encryption prevented users from using other peoples’ passwords—until some hackers figured out to quickly break the encryption. But by that time, Unix programs had become used to storing all sorts of extra information along with the user’s password—including the user’s real name, user ID number, even home and office phone numbers!
When hackers started decrypting passwords, Linux developers had to find a way to separate passwords from user information. The solution they created, which is still in use today, is to store all of the user’s information except the password in the old Unix /etc/passwd
file. The actual passwords were stored in a file that only the root user (administrator) can access named /etc/shadow
.
You shouldn’t notice this abstraction when making basic password changes, but it will become noticeable when you attempt low-level password replacement.
How To Change A Password On Linux That You Know
Changing your password frequently helps keep hackers from breaking into your Linux computer. GNOME or KDE desktop environment users can easily change their password using the appropriate application described below.
GNOME users should click the System menu, go to Preferences, and click About Me. On the screen shown, you can update all of your user information and your password. You can also change your user picture which the GNOME Display Manager (GDM) displays on the login screen.
KDE users should use almost exactly the same method: click System Settings, choose the Personal menu, click About Me, and click Change Password.
Another way to change your password works on every Linux system (and also any Unix system—try it on Mac OS X if you have a system handy). Open a terminal and run the command passwd
.
Whichever program you end up using to change your password, you will need to know your old password—this obviously keeps pranksters from changing your password while you use the bathroom. Many recent Linux distributions include by default a password strength checker—this program won’t let you change your password to a weak password, giving you a little extra security.
How To Change A Password You Don’t Know On Linux
Users frequently ask system administrators for help changing their forgotten passwords. Under normal conditions, this couldn’t be easier on Linux: you’ll use the passwd
program again, but this time you’ll run it as root. The root user is also known as the superuser, so the two commands that follow both start with the abbreviation su for superuser.
How you become the root user differs depending on your distribution and your settings. On Ubuntu and many other systems (including Mac OS X), you need to use the sudo
command with an administrator account. (Most sudo-using Linux distributions make the first user account you create into an administrator account.) To become the root user on a sudo-based system, type the following command and enter your user password: sudo -s
To become the root user on any other Linux system, you need to know the root password. If you’ve forgotten the root password, keep reading this article—we’ll tell you how to recover it. The command to become root is su
. To become the root user, type the following command and enter the root password: su
After you become the root user, run the program passwd
with username of the user who forgot their password. For example, my username is harding so, if I forgot my password, my administrator would run the following command: passwd harding
The passwd command will prompt you for a new password—note that you don’t need the old password if you’re the root user. Here’s an example of exactly what my administrator would see if he needed to change my password on the computer named callisto:
callisto:0:~$ sudo -s
callisto:0:~# passwd harding
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Note, passwd doesn’t show the password as you type it to prevent someone else from seeing it. After you change the password as root, enter the exit
command to end your session.
How To Change The Root Password On Linux
If you know the old root password or you use sudo, changing the root password is really simple: just follow the instructions above for changing a password you don’t know—become the root user and type passwd root
. Note that passwd
doesn’t ask you for the old root password—we’ll use this fact next to reset a root password you’ve forgotten.
More difficult is changing the root password when you don’t know what it is and don’t have access to an administrator account on a sudo-based system. In this case, you have two options:
How To Change A Password On Linux For Root In Friendly Distributions
On Ubuntu and many “friendly” Linux distributions, you can become the root user by booting with a special option, usually called single user mode or recovery mode. This option should appear on your Linux boot menu. Here’s exactly what you need to do:
- Reboot the computer.
- Choose single user mode or recovery mode.
- Wait for the computer to boot until you get to a command line prompt.
- Type
passwd root
to change the Linux root password - Type
exit
to resume a normal boot
How To Change The Root Password On Linux In Secure Distributions
On other less friendly (but slightly more secure) Linux systems, you need to know a few special commands in order to change the root password. Follow these steps:
- Reboot the computer
- On the boot menu, don’t choose any option. Instead, quickly press the
e
key before any option gets selected. The e stands for edit the boot option. - On the boot option edit screen, the top line should start with the word “kernel.” If it doesn’t, use your arrow keys to select the line that does start with “kernel.”
- Go to the very end of the line, add a space, and enter the following text exactly:
init=/bin/sh
- Press Ctrl-X to boot the modified boot option. (Note: this modification won’t persist, so you don’t need to do anything to undo it for the next boot.)
- Linux will do the absolute most minimal boot possible and then give you a command prompt. Because the boot was so minimal, you may need to run an extra command; this command may not work, but it won’t break anything, so don’t worry if you see an error message. Type:
mount /usr
- Now you can change the root password—type:
passwd root
. There’s only one more step to change the Linux root password—reboot the computer by typingreboot
.