Skip to main content

How to Change the Root Password

How to Change the Root Password in Ubuntu

Changing your root password on Ubuntu 16.04 (this works on other versions, along with any Ubuntu server version) is very easy.

Method 1: Through a terminal, while booted (Must have other accounts on the machine)

Step 1: Open a Terminal.

This can be done by either pressing Ctrl+Alt+T, or by finding the Terminal program using the search function. If it’s a VPS or a server, simply SSH in like you normally would.

Step 2: Enter the password change command.

This command is what will allow you to change your root password. First, however, you will need to enter the password of your user account in order to authenticate the change. Of course, this assumes that your account is in the sudoers list, which essentially means that your account is an administrator account. If it is not, you will have to change your password using the second method.
sudo -i passwd
It will then ask you to enter a new UNIX password, and once you enter it, will ask you to repeat the password. Once this is done, you will have successfully changed the password of the root user. Now all you have to do is log out of your regular account and just log in using the “root” username.
There is also a second, more advanced method that can be used if you only had a root account on your ubuntu machine, or if any other accounts are unable to use the sudo command. This method uses grub to get past the operating system altogether, and allows you to change the password of the root user without needing to know any passwords.

Method 2: Grub (No account needed)

Step 1: Enter the grub options screen.

Restart your machine. If Ubuntu is your only operating system on the machine, then hold shift after the bios screen passes to enter the operating system selection menu. If you have more than one operating system on your machine, then this menu shows up automatically. Press the ‘e’ key to enter the grub options screen for ubuntu.

Step 2: Edit the grub option.

When in the editing menu, scroll down to the line starting with the word “linux”, and append the following to the end of the line:
exec /sbin/init
Now press Ctrl+X to boot with this new configuration.

Step 3: Change the root password.

Changing the root password is now possible. Execute the “passwd” command, and enter your new password – re-enter it when prompted. Your root password has now been changed. Simply use the “reboot” command, or if that doesn’t work, use the following command to restart your system to its normal state:
exec /sbin/init

Change Root Password CentOSHow to change the root password on CentOS

This tutorial focuses on CentOS 7 – the procedure for a password reset actually differs between CentOS 7 and previous versions of CentOS, which is why we will only focus on the latest version.
Resetting your root password is not as easy on CentOS as it is on Ubuntu. There are more steps, and each command must be correct, so be careful with your commands.

Step 1: Enter the grub options screen.

This is done by either restarting your machine, or by starting it if it was already off. When the CentOS boot screen appears, press ‘e’ to enter the grub options menu.

Step 2: Edit the grub option.

Scroll down to the line starting with “linux” or “linux16”. Replace the word “ro” with “rw init=/sysroot/bin/sh”. Then press Ctrl+X at the same time to boot using this configuration.

Step 3: Access the filesystem.

Using the command “chroot /sysroot”, we are able to access and perform commands on the filesystem as if we were booted into the operating system. We need to do this in order to access the “passwd” command.

Step 4: Change your root password.

Enter the command “passwd root” to change your root password. It will ask you to confirm the password, which is where you will enter your new password again. Once done, proceed to the next step.

Step 5: Fixing the /etc/shadow file (SELinux only)

If you have SELinux disabled, skip this step. If you do not have SELinux disabled, enter the following command to make sure the new /etc/shadow file that was created when you changed your password is accepted as the new file:
touch /.autorelabel
After this is done, simply type “exit”, followed by another “exit”. If your machine hangs/freezes, just reset your machine. While rebooting, it may take a few minutes for the auto relabeling to occur.
Once you reboot, you should be able to now login as the root user with your new root password!

Change Root Password DebianHow to change the root password on Debian

Changing your root password on Debian is similar to the method used for changing it on CentOS – however, this will work on most versions of Debian. NOTE: If something on your system does not look like what we describe in this tutorial, then you should stop – you may cause your system to become unbootable.

Step 1: Enter the grub options screen.

Do this by restarting your system and pressing ‘e’ once the boot screen shows up. Proceed to the next step when done.

Step 2: Edit your grub configuration.

Scroll down to the line that starts with “linux”, and go to the end of that line, either by pressing the END key on your keyboard, or by manually scrolling to the end of the line. Enter the following to boot into the ‘#’ prompt:
init=/bin/sh
Don’t forget to have a blank space between the previous arguments and the new argument that you just wrote.

Step 3: Mount the filesystem.

Enter the next command to mount your root filesystem in the read/write mode. This is needed in order to be able to edit the root password:
mount -o remount rw /
Once done, proceed to the next step.

Step 4: Change your root password.

Simply enter the “passwd” command to change your root password. Enter, then re-enter your new password when prompted. When done, just reboot your system by using the “reboot” or “exit” command. If it hangs/freezes on this screen, just reset your machine.

Change Root Password FedoraHow to change the root password on Fedora

Fedora has two methods for resetting the root account’s password. One way is through a terminal and an administrator account, and the other way is through a similar method of resetting that was done with CentOS or Debian, involving grub. Here are the steps you need to take to reset your password for both methods.

Method 1: Terminal while booted (Must have other accounts on the machine)

DISCLAIMER: The account with which you log in normally has to be able to execute sudo commands in order to be able to log in as the root account. Otherwise, this will not work, and method 2 will be the only way to reset the root password.

Step 1: Open a terminal.

Open your menu and search for ‘Terminal’. Open it. SSH into your machine if it is a server or a VPS.

Step 2: Escalate your terminal session to the root account.

Enter the following command to escalate your terminal session to the root account (this will only work if your user account is on the sudoers/administrators list):
sudo su
Enter your user account’s password, and you should be logged in as the root account.

Step 3: Change the password.

Changing the password now is a piece of cake – just use the “passwd” command to change the password as you normally would with any other user account. When done, simply execute the “exit” command to end your session as the root account.

Method 2: Grub (No account needed)

Step 1: Enter the grub options menu.

Restart your machine, then press ‘e’ when choosing an operating system to enter the grub menu. Once in, search for the line starting with “linux”, “linux16”, or “linuxefi”. Go to the end of the line and add the following:
rw init=/bin/bash
Then press Ctrl+X to boot into the system.

Step 2: Change the password for the root user account.

Now all that needs to be done is to execute the “passwd” command, which will output something similar to this:
Changing password for user root.

New password: _
Just enter your new password, then enter it again to confirm.

Step 3: Fix the SELinux context of the /etc/shadow file.

Like the CentOS guide, you need to run the auto label script in order to have your password change take effect. This is done by executing the following command:
touch /.autorelabel
You can now reboot your machine either by executing the following command:
/sbin/reboot -f
This first reboot while relabeling will take a while. When you finish rebooting, your new password will be what logs you into the root account.

Comments

Popular posts from this blog

How to SSH to the VM instance in OpenStack

Alright, so now you have purchased Dedicated Server at www.vcclhosting.com and OpenStack installed and running. Now what? Of course the first thing you want to do is create a Virtual Machine Instance you can play with. But hold your ponies little boy, you might want to read on first, as you might not be able to connect to any of your VMs if you did not read carefully! Common Mistake! It is a common behavior of a new OpenStack user upon logging into dashboard to create a new instance via the menu w/o setting up a new Key Pair first. If you didn't attach a key pair in your VM instance, you will not be able to connect to it! So the first thing you might want to do is create a new Key Pair. This is basically a PEM file that you are going to use in able to authenticate to the server instead of shoving your usename/password in the SSH console. Wtf is PEM? PEM is a file format that may consist of a certificate (aka. public key), a private key or indeed both concatenated to

How to Install Apache Tomcat 8 On Debian

In this tutorial, we will show you how to install Apache Tomcat 8 On Debian, manually.know more with www.vcclhosting.com Blog Environment : Debian 7 JDK 1.8 Apache Tomcat 8 Buy Cloud KVM Server  for best results and 24-7 support. P.S Assume the JDK 1.8 is installed in  /opt/jdk  folder. Refer to this guide to install Oracle JDK 8 on Debian. Note On Debian 7, the Tomcat 8 is not included in the default apt-get repository. Note This guide should work in other Debian derivatives like Ubuntu or Mint. 1. Get Tomcat 8 1.1 Visit Tomcat 8 page and download the tar.gz file. 1.2 In this example, we get the version 8.0.30 via  wget  command. $ cd /opt $ sudo wget http://www.eu.apache.org/dist/tomcat/tomcat-8/v8.0.30/bin/apache-tomcat-8.0.30.tar.gz Copy 2. Extracts to /opt/tomcat8 2.1 Extracts it to path  /opt/tomcat8 $ pwd /opt $ sudo tar -xvzf apache-tomcat-8.0.30.tar.gz $ mv apache-tomcat-8.0.30 tomcat8 $ ls -lsh 4.0K drwxr-xr-x 6 root root 4.0K

Now Intel® Core™ i7-8700 Hexa-Core Coffee Lake Servers available

                   Intel® Core™ i7-8700 Hexa-Core Coffee Lake incl. Hyper-Threading Technology Servers are available at www.vcclhosting.com and www.vcclcloud.com .         High Speed and extra Storage space with Hyper threading technology gives extra powerful speedy server ,Start today and power up your business with VCCL Dedicated Servers. Dedicated Root Server Pricing SERVER CPU RAM DISK LOCATION PRICING ORDER DS1-Intel®Core™i7-6700 Quad-Core Skylake 32 GB DDR4 SSD 2x500 GB EUROPE $125/mo CONFIGURE DS2-Intel®Core™i7-6700 Quad-Core Skylake 32 GB DDR4 HHD 2x4 TB EUROPE $145/mo CONFIGURE DS3-Intel®Core™i7-6700 Quad-Core Skylake 64 GB DDR4 SSD 2x 250 GB EUROPE $165/mo CONFIGURE DS4-Intel®Core™i7-6700 Quad-Core Skylake 64 GB DDR4 HHD 2x 2 TB EUROPE $185/mo CONFIGURE DS5-AMD Ryzen 7 1700X Quad-Core "Summit Ridge" 64 GB DDR4 SSD 2x 500 GB EUROPE $199/mo CONFIGURE DS6-Intel® Xeon® E3-1270 v3 Quad-Core Haswell 32 GB DDR4 HHD 4x 10 TB EUROPE $ 145/m