How to change your Linux user password without root user
Introduction⌗
I have two computers in my house: one is for work and the other is personal. Normally, I use the work computer for most of the days when I am at home. When I have personal work, which has been rare lately ~and please, send me paid work!~, I boot up my personal computer. However, today, with all the effort in thinking back, I could not remember my login password. I run endeavour OS
which is an Arch Linux
based distribution. I could not use the root
user because clearly, that’s unlocked with this forgotten password. I will show you how I changed my password using a live installation USB of endeavour OS
and chroot
.
Requirements⌗
- Live installation USB or disc of the distribution you’re running.
Steps⌗
Load the live disc and open up a terminal⌗
This is like a normal install. However, we are only interested in having a terminal we can use on the same machine.
Create a temporary location and mount it on any of your sd*⌗
Now, before you start doing this, you have to be the root
user. So use the sudo su
command to do it:
[root@liveusb liveuser]# sudo su
Next, you want to create a folder /mnt/arch
and this is what you will mount to your disks:
[root@liveusb liveuser]# mkdir /mnt/arch
List all your disks. Here, I took a gamble and mounted in my sda1
then sda2
. The reason is I wanted to ensure that when I list all the files, I have the following output:
[root@liveusb liveuser]# lsblk
sda sda1 sda2
[root@liveusb liveuser]# mount /dev/sda1 /mnt/arch
[root@liveusb liveuser]# cd /mnt/arch
[root@liveusb arch]# ls
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
Next you want to mount a bunch of other locations on the disk:
[root@liveusb arch]# mount -t proc proc proc/
[root@liveusb arch]# mount -t sysfs sys sys/
[root@liveusb arch]# mount -o bind /dev dev/
[root@liveusb arch]# mount -t devpts pts dev/pts/
Lastly, you use chroot
. This takes you to the root location. You’ve access to the command passwd
and you will pass in the user you want to change the password for:
[root@liveusb arch]# chroot /mnt/arch/ /usr/bin/bash
[root@liveusb /]#
If you don’t know the user, then you can check the users you have if they have passwords:
[root@liveusb /]# cat /etc/shadow
youusername:$1$KNO15fOz$xMef3ieizYZmKrbhK1IAR/:16767:0:99999:7:::
Lastly, we change the password for the user:
[root@liveusb /]# passwd yourusername
New password:
Retype new password:
passwd: password updated successfully
[root@liveusb /]#
Your password is updated. Shut down the computer, remove the live installation USB or disc. Power on, log in with your user and the password you just set.
Conclusion⌗
We have seen how to change the password for a linux user when we have a live USB or disc and the chroot
command.