Uh-oh! If you’re forgetful like me, chances are that you may come into this situation one way or another in the not so distant future. Bless you if you never do. I really hope you don’t. Write that password down somewhere. Safe. Not on a piece of paper please. In any case, if it does happen to you one day, don’t fret. You’re not alone. And there’s a solution.
Here’s what I did to be able to login again to my Linux desktop. This happened on my Manjaro Linux. Recently. It is running on my Ubuntu as a guest operating system via VMwareยฎ Workstation 15 Player. This trick should work on Ubuntu too, I think. Heck, might be good for Debian as well. I know I’ve tried a similar trick before on either SuSE or Mandrake a long time ago.
First up, the moment I started the guest operating system from the VMware application, I clicked on that empty black screen that follows after straight away and hit the Esc button. Once I had done that, I was brought to this screen.

That is the GRUB menu. Or prompt. Or whatever it is they call it nowadays. If you don’t see that after hitting the escape button, you might be greeted with the desktop login screen a few seconds later. Reboot then do the click-escape sequence again. Quickly this time.
I selected ‘E’. Do that with the keyboard. Not the mouse. E is for the Edit Boot Options where I can then edit things so I can boot into single-user mode as root. No passwords asked. ๐

That screen above is not yet the single-user mode. That is just what happens after pressing the E key.
Next I looked for the line that has the linux kernel. It’s somewhere down there after all that text. Scroll down using arrow keys. It starts or looks something like the following.
linux /boot/vmlinuz

The text along that line is quite long. I went to the very end of this line, making sure I’m still on the same line, and added the following. There is a space before, of course.
init=/bin/bash
Make sure this is appended on the same line!

Note: I’m too lazy to bring up Gimp and edit the images to highlight the lines right now. Looking closely, it should be fairly obvious which line it is I’m talking about.
Pressing the Ctrl-x or F10 keys will now resume the boot. This time it dropped me to a terminal in single-user mode. In this mode the system is operating as the root user. At this point the filesystem will be in read-only mode. For changes to work it needs to be in read-write.
Now I re-mounted the root filesystem with read/write permission using the following command.
:~$ mount -o remount,rw /
That screenshot down there is showing the command prompt once I was in single-user mode. Here I can type whatever commands. Let’s stick to getting that user password reset though.

The command to change password is passwd
. This command alone will allow me to change the root password. However, if I don’t want to change the root password, I will follow the command with the username. Something like this:
:~$ passwd joseyamut
Enter the command and I will be greeted with a prompt that says:
Enter new UNIX password:
Followed by another prompt to retype the password. So the new password has to be typed in twice. If the change was successful or not it will say so. The text hints will be quite obvious.
If for some reason you cannot remember the username, that’s really pushing it. ๐ ๐ Go look it up from the file called /etc/passwd. Go through the file. Each user will be on its own line within the file. Normally, the non-system users will be at the bottom of the list, but that all depends.
:~$ cat /etc/passwd
Or use the less
command to have the ability to scroll up/down if the list is too long. Press ‘q’ to quit/exit from it.
:~$ less /etc/passwd
Okay, having done all of the above, I can now reboot. The shutdown
command might not work here. Use reboot
instead.
:~$ reboot -f
This should now be a normal boot. I waited until my Manjaro KDE login screen came up and typed in my new password. And then I’m back inside!
People might wonder, why go through all this? Just go to a terminal and change the password as root. Now the reason why I chose this approach instead of calling the TTY (That’s with the Ctrl-Alt-F1 … F2 … key combo) is because in this install I chose to have the root password be the same as my user’s. Hence, if I can’t remember my user password, what luck do I have with root? Going to TTY, it will ask me for the root password before I can change a user’s password. I will still be stuck at that login prompt too whether on GUI or a terminal.
Also GRUB can have a password that is not related to root. If that is something that’s been forgotten too then going into GRUB edit mode like this won’t work without that password. It should be possible to instead boot from a live Linux distro, then do the changes from there. You need to know the correct partition, mount it, then chroot
to make the changes. Okay, I’ve not done that before yet, as far as I can recall, but it should be very possible.
Similar Posts:
- > grub basics – booting from command prompt December 20, 2006
- > GRUB2 Issues With Ubuntu 12.04 Installation May 2, 2012
- > Make Plymouth Start Earlier In The Boot Process November 18, 2011
- > booting M$ Windoze from another physical drive August 1, 2006
- > no administrator mode on kcontrol September 2, 2006