Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an external hdd partitioned into two. One of the partitions has Linux (Ubuntu) installed on it (bootable). The thing is I have forgotten the password of it's user (single user).

How can I reset the password of user by plugging the external hdd to another Linux machine and then editing some file, using some command through terminal, changing the bash(remember doing something similar long time ago), or something else?

And I do not want to get into Grub etc. Booting through that drive is not an option (although it is but I am not willing to get into it and don't want to restart the running("another") Linux machine).

share|improve this question

marked as duplicate by jasonwryan, michas, Anthon, slm, rahmu Dec 15 '13 at 22:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 4 down vote accepted

Even though michas gave you the optimal answer, it still involves booting from the external hard drive, which for some reason you seem against. Here's a method you can use from another Linux system without booting from the external drive. I assume that your Linux partition on the external HDD is /dev/sdb1, modify the following as needed. Run this code on your other Linux installation:

[root@host]# mount /dev/sdb1 /mnt
[root@host]# chroot /mnt
[root@host]# passwd user
Enter new Unix password:
Retype new Unix password:
passwd: password updated successfully
[root@host]# exit
[root@host]# umount /mnt
share|improve this answer
    
chroot is indeed safer than manually editing /etc/shadow. –  michas Dec 15 '13 at 21:43

No need to put the disk into another machine.

I assume your computer uses Grub as a bootloader. (The OS-choosing thing at the very beginning of the boot process.)

You can use it to temporary edit the linux command line adding init=/bin/sh. This will instead of booting the whole system just open a root shell, which allows you to set a new password with passwd username.

After another reboot everything should be fine again.


If you really insist on setting another password using another computer, you have to mount that disk and edit the file $mountpoint/etc/shadow, which stores the hashed password. (It should be possible to paste a line from the other computer for a user you know the password.)

A safer way to achieve the same is first using chroot $mountpoint and then changing the password using passwd username. This will also change the same file, but you can be sure it stores the password in the correct way and don't risk an invalid line.

share|improve this answer

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