How do I log into my Linux laptop if I have forgotten both the username and password?

  • What Linux flavor is it? Do you know what the boot-loader (Grub or Lilo) is? – Caleb Aug 1 '11 at 20:43
  • It is Ubuntu 9.04 server, Has GRUB v 0.97 – Ankur Agarwal Aug 1 '11 at 20:44

You can drop into single mode from Grub. During boot press Esc on the Grub boot screen when it prompts you to. It may just show you Grub with listings of each kernel - if that's the case don't press Esc.

From here select the first entry and press e to edit that entry. Page down to the line that starts with kernel and press e again.

This will allow you to edit the entire line. Scroll to the right until you reach the end and remove splash quiet from the line, replacing it with single. Press Enter to accept the changes and press b to boot into the modified kernel line. This will boot you into single user mode and should drop you into a root shell once the boot has completed.

From here you can add users to the system, change user passwords, etc.

  • +1 A much better answer than what I was going to suggest. – Nathan Osman Aug 1 '11 at 21:24
  • 1
    If the above fails -- unlikely if GRUB is password -- boot from an Ubuntu livecd (preferrably 9.04 server), mount your Ubuntu partitions, then chroot into it. You can then issue the passwd command to reset root, your user, etc. – laebshade Aug 13 '11 at 15:40

You might do as Marco suggested, but his will not work on all distros. More precisely, it will not work without the need of giving the root password on systems using openrc.

The more generic way, without using any other bootable media, is to append init=/bin/bash or init=/bin/sh to boot options (that's where you'd put single following Marco's answer).

Another option, maybe a last resort, is to boot from a removable media (like livecd), mount the root partition of your system and either chroot to it or do a dirty job on /etc/shadow. By this I mean editing it and removing the password hash field. But it is a dirty (read: dangerous) method: Firstly, /etc/shadow is a vital security file and an error in its structure can create a security breach or just break a lot of things. To prevent errors, it should only be edited using vipw -s command - but this is only possible when you chroot into the system. Other problems could be caused by a conflict/error detected by advanced security mechanisms working on the system. But I haven't used such so far, so cannot tell what those problems might be.

  • some dirty job like what?? – amyassin Aug 12 '11 at 13:21
  • 1
    I didn't want to write about it in the answer, because of the dirtyness: I meant to remove the password hash, then login with no password and set a new one. – rozcietrzewiacz Aug 12 '11 at 14:04
  • I think it is the best solution... what's dirty about it?? – amyassin Aug 12 '11 at 14:09
  • 1
    Editing /etc/shadow by hand is dangerous: one can easily mess up the system or maybe even create a conflict in some advanced security mechanism. Ok, I'll update the answer. – rozcietrzewiacz Aug 13 '11 at 10:43

It was long time, I have not used a Ubuntu 12.04 Linux box. I forgot its login id. I tried the following approach and got the login id.

Stop at the Grub boot loader, look for options to edit and to fall back to the command-line. In my case for edit it was 'e', and for command line it was 'c'. After pressing 'e' edit key the options for boot and options for command line changes to F10 and Ctrl+C or F2.

Use any method and drop to boot loader (grub) command shell. Then type ls. It will show the partitions on the disk.

#grub> ls
(hd0) (hd0,msdos5) (hd0,msdos1)
#grub>ls << (the partition of your boot kernel, u can see in the grub list against root option. it will be " root = (hd0,msdos1) >>

Otherwise also, you just ls and check /etc/issue or any relevant files for information.

in my case my linux was installed in (hd0,msdos1). Check for the file passwd in etc

#ls (hd0,msdos5)/etc/passwd  


#cat (hd0,msdos5)/etc/passwd

Check the frag end of the file for your user name. Boot normally and use the user name to login.

  • Doesn't solve the forgotten password. – Pavel Šimerda Jul 17 '14 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.