5

My current ubuntu Administrator account has Automatic login ON.I was wondering if there was a way to recover the current password with my account logged in without recovering it from GRUB.

ragmha
  • 180
  • 1
  • 1
  • 7
  • 1
    You can't really "recover" your password from recovery mode, you merely can reset it. Linux doesn't store the passwords themselves, but hashes of there only. – s3lph Jan 31 '15 at 22:49
  • I am currently logged in,so the only option is to reset my password through grub ? – ragmha Jan 31 '15 at 22:51
  • No, simply run sudo passwd <username> to set a new password for , which of course requires that you know your sudo password... – s3lph Jan 31 '15 at 22:52
  • My current password and sudo password are same.So how may i set a new password ? – ragmha Jan 31 '15 at 22:55
  • @Rgbm21 sudo nano /etc/shadow but passwords are encrypted. SHA-512 – mertyildiran Feb 01 '15 at 01:46
  • @Rgbm21 if I understand correctly. You are already logged in with your account. But you can't use sudo because you don't know the password of your account. I suppose, it means you can not recover your password. – mertyildiran Feb 01 '15 at 01:49
  • @MehmetMertYidiran Yes.So the only option is Resetting it ? – ragmha Feb 01 '15 at 03:18
  • @Rgbm21 the only option reinstalling Ubuntu completely in your situation. But if you have another account with administrator privileges you don't have to reinstal Ubuntu but even with another administrator account you can not recover the account in your question. – mertyildiran Feb 01 '15 at 03:26

2 Answers2

8

Reading the comments under your question, it seems as you have lost total access to your root account. So you can neither run sudo passwd from a normal session, nor can you access the recovery shell, which requires the root password. So you have the following options left:

Either reinstall your system...

or reset the password from a live USB/DVD system. Follow these steps:

  1. If you already have an Ubuntu DVD or USB stick, skip to step 4.
  2. If you don't have an Ubuntu- or other Linux-ISO file, download one, e.g. the current Ubuntu release.
  3. Burn it to a DVD (e.g. with Brasero) or extract it to an USB stick (e.g. with Startup Disk Creator or any similar program which doesn't ask for root permission)
  4. Boot the DVD or USB and select "Try Ubuntu without installing"
  5. From within the live system, open a terminal and find out, which is your system partition: sudo parted -l. This will list all your partitions, of all connected drives. Your USB stick partition will be mounted as /, so it'll be another drive. Search for an EXT4 partition, which (when using Legacy BIOS) has the boot flag and fits the size of your system.
  6. Mount this partition r/w: sudo mount /dev/sdXY /mnt -o rw
  7. Open a root shell in the mounted system: sudo chroot /mnt
  8. Reset the root password: sudo passwd, enter new password twice.
  9. exit
  10. Unmount the system partition: sudo umount /mnt
  11. Reboot into your system.
s3lph
  • 14,314
  • 11
  • 59
  • 82
2

booting into livecd to change password is not necessary. It's enought to:

  1. when system is booting, in grub menu - enter via "e" key to edit command line.
  2. add there something like init=/bin/bash
  3. when you have prompt - change password using passwd command. sometimes it's necessary to remount root partition into rw (mount -o remount,rw)
  4. after change - do "sync" command to write change into disk, and then reboot system.

Sometimes it's worth to do backup of /etc/shadow file (cp /etc/shadow /etc/shadow.backup) - for example when you really need to recover old password, because your home directory is encrypted with it... - then after loggin you can try to find your password using john tool from old shadow file.

undefine
  • 478