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).
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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:
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2b0adadb682aaadb1b6">[email protected]</a>]# mount /dev/sdb1 /mnt [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681a07071c2800071b1c">[email protected]</a>]# chroot /mnt [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f6d70706b5f77706c6b">[email protected]</a>]# passwd user Enter new Unix password: Retype new Unix password: passwd: password updated successfully [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="11637e7e6551797e6265">[email protected]</a>]# exit [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcced3d3c8fcd4d3cfc8">[email protected]</a>]# umount /mnt
Method 2
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.
Method 3
Just to extend a little Michas answer.
For everyone who struggles with changing the password on another architecture (e.g. ARM) and cannot defeat ‘/bin/bash’ no such file or directory there is a solution.
WARNING: This solution is actually “last hope” and not
recommended to use (please, read)
The exact steps:
- Open the
/etc/shadowcomputer where the password is known.
sudo cat /etc/shadow
- Choose the user you know the password of. It might looks like:
username:$6$rNA/BOfW$i9jrx/yF9bQfj.XOSNkvMlAzObxW345345EYzQx/5nSsl4cHiNtr8aky91/:18265:0:99999:7:::
- Copy the whole string from first
:until the last three:::i.e.:
$6$rNA/BOfW$i9jrx/yF9bQfj.XOSNkvMlAzObxW345345EYzQx/5nSsl4cHiNtr8aky91/:18265:0:99999:7
- Mount the root file system of the computer where you want to change the password. And replace the hash of the old password for the desired user with the copied one.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0