Thursday, April 14, 2016

[Quick Tips: Root Password Reset] : How to reset or recover root user password

Today, we will see how to reset or recover root user password in Linux.

Note: You can reset the password only if you have physical access to the system. For remote systems and VPS, you should ask the service provider’s help.
For the purpose of this tutorial, we’re going to use the following distributions:
  • Arch Linux 2016 ;
  • CentOS 6.x & 7.x
  • Ubuntu 15.10.
First, we will start from Arch Linux.

1. Reset root user password in Arch Linux

This method was tested in Arch Linux 2016 version, however It may work on earlier versions and other Arch based Linux distros too.
At the GRUB boot menu, select the Arch Linux entry by using the arrow keys.
Arch Linux 2016 [Running] - Oracle VM VirtualBox_005
Press e to edit. Find the line that starts with word linux:
linux          /boot/vmlinuz-linux  root-UUID=d474f2-e6a2-4cc3-9899-aa98af13  rw  quiet
At the end of the above line, type the following line:
init=/bin/bash
Refer the following screenshot.
Arch Linux 2016 [Running] - Oracle VM VirtualBox_001
After appending the above line, press CTRL-X or F10 to boot. This change will be only temporary and will not be saved in your boot menu.ist file.
Now, you reached the single user mode.
Type the following command to mount your root (/) file system in read/write mode.
mount -n -o remount,rw /
Then, change your root user password using command:
passwd
Enter the new password twice.
Arch Linux 2016 [Running] - Oracle VM VirtualBox_002
Finally, type the following command to apply the changes and start your Arch Linux in to normal mode.
exec /sbin/init
You can now log in to your Arch Linux server using the new root user password.
Arch Linux 2016 [Running] - Oracle VM VirtualBox_004

2. Reset root user password in CentOS 7.x

We can do it in two methods. Both are slightly different, but easy. This method will also work on RHEL 7.x, Scientific Linux 7.x.

Method 1:

Power on your CentOS 7 server. At the boot menu, select the Kernel you want to boot up and press e to edit the selected item.
CentOS 7 -1 [Running] - Oracle VM VirtualBox_001
Find the line rhgb quiet :
CentOS 7 -1 [Running] - Oracle VM VirtualBox_002
and replace it with init=/bin/bash
CentOS 7 -1 [Running] - Oracle VM VirtualBox_003
Then press CTRL+X to enter in to single user mode.
Type the following command to mount root (/) fiel system in to read/write mode.
mount -o remount,rw /
CentOS 7 -1 [Running] - Oracle VM VirtualBox_005
Now, change the root user password with command:
passwd root
Enter the new password twice.
CentOS 7 -1 [Running] - Oracle VM VirtualBox_017
Finally, run the following command to update SELinux:
touch /.autorelabel
Then, type the following command to apply changes and restart CentOS 7:
exec /sbin/init
CentOS 7 -1 [Running] - Oracle VM VirtualBox_006
Now, you’ll be able to log in to CentOS 7 with new password.
CentOS 7 -1 [Running] - Oracle VM VirtualBox_004

Method 2:

At the GRUB boot menu, select the boot entry and press e to edit the selected item.
CentOS 7 -1 [Running] - Oracle VM VirtualBox_001
Find the line ro :
CentOS 7 -1 [Running] - Oracle VM VirtualBox_001
Change the ro line to rw and add an extra line init=/sysroot/bin/sh
CentOS 7 -1 [Running] - Oracle VM VirtualBox_002
Press CTRL+X to enter in to single user mode.
Then type:
chroot /sysroot/
CentOS 7 -1 [Running] - Oracle VM VirtualBox_003
Then change the root user password with command:
passwd root
CentOS 7 -1 [Running] - Oracle VM VirtualBox_004
Update SELinux with command:
touch /.autorelabel
Reboot your system.
exit
reboot
Now, you can log in to the system with new password.

3. Reset root user password in CentOS 6.x

If you want to reset root user password for CentOS 6.x systems and older versions, the follow these steps. This method will also work on RHEL 6.x, Scientific Linux 6.x.
At the boot menu, select the Kernel you want to boot up and press e to edit the selected item.
CentOS 6.5 Minimal [Running] - Oracle VM VirtualBox_001
Select second line (Starts with the word Kernel) and press e to edit that line.
CentOS 6.5 Minimal [Running] - Oracle VM VirtualBox_002
Go to the end of the line and type to start in to the single user mode.
CentOS 6.5 Minimal [Running] - Oracle VM VirtualBox_004
Then, press ENTER key and press b key to boot into to single user mode.
Mount the root (/) file system in read/write mode:
mount -o remount,rw /
Change the root password with command:
passwd root
Finally restart your CentOS 6 server.
sync
reboot
CentOS 6.5 Minimal [Running] - Oracle VM VirtualBox_005
You can now able to login with new password.
CentOS 6.5 Minimal [Running] - Oracle VM VirtualBox_006
That’s it.

4. Reset administrative user password in Ubuntu

I tested this how-to on Ubuntu 15.10 server, however it might work on other Ubuntu versions like Ubuntu 15.04/14.10/14.04 etc.
You can do it in two methods.

Method 1:

At the Grub boot loader menu, select the Kernel you use and press e to edit the entry.
Find the line that starts with word linux. Add the following line at the end.
init=/bin/bash
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_008
Then, press CTRL-X or F10 to boot in to single user mode.
Type the following command to mount root (/) file system in to read/write mode.
mount -o remount,rw /
Then, change the password of your administrative account using command:
passwd sk
Here sk is my administrative account.
Type the new password twice.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_010
Finally, type the following command to start Ubuntu with updated password.
exec /sbin/init
Now, you’ll be able to log in with new password.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_011
This method is so easy. Still curious to know another way to reset the password, read on.

Method 2:

At the GRUB boot leader menu, select Advanced options for Ubuntu entry.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_012
Select the second option i.e recovery mode.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_013
You’ll see the list of recovery options. Select root Drop to root shell prompt option.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_014
Now, you’ll be reached to the single user mode.
Type the following command to mount root (/) file system in read/write mode.
mount -o remount,rw /
Then change the password of the administrative user, for example sk, using command:
passwd sk
Enter the new password twice.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_017
Then, type exit to return back to the recovery menu. Select Resume to start your Ubuntu system.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_018
You might see the following message that says: You are now going to exit the recovery mode. Press ENTER to continue.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_019
That’s it. You can now able to login with new password.
Ubuntu 15.10 server [Running] - Oracle VM VirtualBox_020
All of the above methods should work for both Desktop and server editions.

What if I don’t know the user name?

I don’t want to reset the root user password, but for the other user. How can I do it? Or You might ask I am going to reset the password of my client system, and we both don’t know the username. Is it possible to reset the password of a specific user? Yes, you can.
After entering into the single user mode, you can view the list of existing users with command:
cat /etc/passwd
Sample output:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false
syslog:x:104:109::/home/syslog:/bin/false
messagebus:x:105:110::/var/run/dbus:/bin/false
uuidd:x:106:111::/run/uuidd:/bin/false
sshd:x:107:65534::/var/run/sshd:/usr/sbin/nologin
sk:x:1000:1000:sk,,,:/home/sk:/bin/bash
Or, you can only list the usernames with command:
awk -F':' '{ print $1}' /etc/passwd
Sample output:
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
systemd-timesync
systemd-network
systemd-resolve
systemd-bus-proxy
syslog
messagebus
uuidd
sshd
sk
The above commands are same for many Linux distributions. That’s it. Pick the username of your choice and reset the password.

Conclusion

In this tutorial, we have learned how to reset the root user password, and also the normal user’s password. Do not blindly trust that you’re safe after setting up a strong password for your root account and as well as for your system accounts. As we can see in this tutorial, the passwords can be easily reset within few minutes, no matter it’s a root or normal user. We must be more careful and encrypt our data, partition and of course we should setup a strong password for GRUB boot loader in order to protect our system.
In our next articles, we will see how to set up password for GRUB boot loader and other security methods to protect our systems.
If you think this tutorial useful, please share it on your social networks and support us.
Thanks for reading! Cheers!!

 

 

 

How to reset or recover root user password in FreeBSD 10.2

Today, I forgot the FreeBSD 10.2 root user password. I tried hard to remember it, but no luck. I know how to reset the root user password in Linux, however I am new to Unix-like operating systems. I have been using FreeBSD just for few weeks now. So, I don’t have a clue how to do it. After a bit of googling and testing, I did it successfully. Here is the procedure for how to reset root user password in FreeBSD 10.2.
Be mindful that this method will only work if you have the physical access to the server. For remote systems and VPS, you must need the service provider’s help. If you have physical access to your FreeBSD server, then follow me.
Power on your FreeBSD server. At the boot menu, press number in your keyboard. Refer the screenshot
FreeBSD 10.2 [Running] - Oracle VM VirtualBox_009
Then, the following message will appear. Just press Enter to continue.
Enter full pathname of shell or RETURN for /bin/sh:
FreeBSD 10.2 [Running] - Oracle VM VirtualBox_010
Now, you’ll be reached the single user mode without root user password.
After reaching the single user mode, you need to mount the root (/) file system in read and write mode.
To do so, run:
mount -u /
mount -a
FreeBSD 10.2 [Running] - Oracle VM VirtualBox_011
Now, setup new password to the root user using command:
passwd
Enter a new password twice.
FreeBSD 10.2 [Running] - Oracle VM VirtualBox_013
Finally, exit from the single user mode with command:
exit
Or, reboot your system using the following commands:
sync;sync
reboot
Similarly, you can reset the any user’s password in single user mode. To reset the other user’s password, for example ostechnix, just use:
passwd ostechnix
And the rest is same as described above
That’s it. You now know how to reset the password for root user. If you find this tutorial helpful, please share it on your social networks and support us. For latest articles and updates, subscribe to our newsletter service.


No comments: