If you have forgotten the password to your Ubuntu Linux server account, you do not necessarily have to go back to square one and reinstall the whole operating system. It is possible to recover and reset the server password, whether it be the root user account or a normal user, even without the old password. In this tutorial, we will take you through the step by step instructions of recovering a forgotten root or normal account password on an Ubuntu server.
In this tutorial you will learn:
- How to reset password via recovery mode
- How to reset password via kernel boot parameters
|Requirements, Conventions or Software Version Used
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Reset password via recovery mode
If you already have terminal access, simply run the
passwd command to choose a new password for the desired user. This example command would reset the password for user
# passwd linuxconfig
If you do not have access to the terminal because you can’t remember your username or password and have disabled root login, then you can follow the step by step instructions below to reset your forgotten account password:
- Power off the machine if it is currently on. Now boot it up while holding the
Shiftkey on your keyboard. This will load the GRUB boot menu. Select “Advanced options for Ubuntu” from the boot menu.
- On the next menu, load the latest kernel in recovery mode.
- Next, select to “Drop to root shell prompt.” This will allow you to execute commands as root.
- You can now view the
/etc/passwdfile for a list of usernames in case you have forgotten yours. And then you can use the
passwdcommand to reset the user’s password.
# cat /etc/passwd # passwd linuxconfig
- Alternatively you can set a password for the root user by executing
passwdwith no other options.
- Once you are done, reboot the system and you can log in to the account with the new password.
Reset password via kernel boot parameters
Resetting an account password on Ubuntu server via kernel boot parameters is a little more tricky but may be necessary if you do not have access to recovery mode. We will need to once again boot into the GRUB boot menu, but this time we will add a temporary kernel boot parameter that allows us to reset an account password.
- First thing you’ll need to do is reboot the machine and access the GRUB menu. This can be done by holding down the
Shiftkey as the computer is first booting up. Once the menu appears, use your arrow keys to highlight the “Ubuntu” selection.
- Next, press
eon your keyboard to edit the parameters.
- Using your arrow keys once again, scroll down a bit until you see a line that begins with
linux /boot/vmlinuz.... We will need to make some small changes to this line. Use the screenshot below for reference so you can make sure you’ve found the correct line.
- The last part of this line is
ro quiet splash $vt_handoff. We will need to replace this text with the following line. Make sure to first backspace the current settings, then type these new ones.
This will give us write permissions as well as a bash shell, so we can use the usual Linux commands to change the root password.
- Once you have made these changes, press the
F10key to save the changes and reboot your system. You will be brought back into a bash prompt, but only on this first reboot. Subsequent machine boots will be back to normal.
- Your root partition should be automatically mounted, with read and write permissions. You can verify this by executing the
mountcommand. If it’s not already mounted, use the following command below to mount it.
# mount -n -o remount,rw /
- Now, simply use the usual
passwdcommand to set a new root password or specify the user whose password you want to reset.
- When done, we just need to reboot the system. The usual
shutdowncommands will not work. Instead, execute the following command to reboot the system and load into the operating system like usual.
# exec /sbin/init
That’s all there is to it. Your computer should boot up like normal, and you will be able to login to the root account (or use commands with sudo) while specifying the password you just set.
In this tutorial, you saw how to reset the root or normal account password on an Ubuntu Linux Server. Ubuntu gives us a couple of options to perform this recovery, whether you use the recovery mode or editing kernel parameters is up to you, and you should pick whichever method is available on your system.