Changing the root password in linux

Содержание
  1. How to change root password in Ubuntu Linux
  2. How to change root password in Ubuntu
  3. How to disable your root account on Ubuntu
  4. Understanding passwd command option
  5. A note about root password on an Ubuntu server/desktop
  6. How to Change the root Password in Linux
  7. How to Change the Root Password in Ubuntu
  8. Method 1: Through a terminal, while booted (Must have other accounts on the machine)
  9. Step 1: Open a Terminal.
  10. Step 2: Enter the password change command.
  11. Method 2: Grub (No account needed)
  12. Step 1: Enter the grub options screen.
  13. Step 2: Edit the grub option.
  14. Step 3: Change the root password.
  15. How to change the root password on CentOS
  16. Step 1: Enter the grub options screen.
  17. Step 2: Edit the grub option.
  18. Step 3: Access the filesystem.
  19. Step 4: Change your root password.
  20. Step 5: Fixing the /etc/shadow file (SELinux only)
  21. How to change the root password on Debian
  22. Step 1: Enter the grub options screen.
  23. Step 2: Edit your grub configuration.
  24. Step 3: Mount the filesystem.
  25. Step 4: Change your root password.
  26. How to change the root password on Fedora
  27. Method 1: Terminal while booted (Must have other accounts on the machine)
  28. Step 1: Open a terminal.
  29. Step 2: Escalate your terminal session to the root account.
  30. Step 3: Change the password.
  31. Method 2: Grub (No account needed)
  32. Step 1: Enter the grub options menu.
  33. Step 2: Change the password for the root user account.
  34. Step 3: Fix the SELinux context of the /etc/shadow file.
  35. How to change root password on Debian Linux
  36. How to change root password on Debian Linux
  37. Debian Linux change root password command
  38. Slightly different procedure for changing passwords in Debian Linux
  39. Conclusion

How to change root password in Ubuntu Linux

I am a new Ubuntu Linux server admin. How can I change root password in Ubuntu Linux server using the bash shell over ssh based session?

By default, the root user account password is locked in Ubuntu Linux for security reasons. As a result, you can not login using root user or use a command such as ‘su -‘ to become a SuperUser.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Ubuntu
Est. reading time 1m

You need to use the passwd command to change the password for user accounts on Ubuntu Linux. A typical user can only change the password for his/her account only. A SuperUser (root) can change the password for any user account. Your user account info stored in /etc/passswd and an encrypted password stored in /etc/shadow file.

How to change root password in Ubuntu

The procedure to change the root user password on Ubuntu Linux:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

  1. Type the following command to become root user and issue passwd:
    sudo -i
    passwd
  2. OR set a password for root user in a single go:
    sudo passwd root
  3. Test it your root password by typing the following command:
    su —

How to disable your root account on Ubuntu

One can disable the root account by typing the following command:
$ sudo passwd -dl root
OR
$ sudo passwd —delete —lock root
Sample session from the above commands:

Understanding passwd command option

  • -d OR —delete : Delete a user’s password (make it empty for root user). This is a quick way to disable a password for an account. It will set the named account passwordless.
  • -l OR —lock : Lock the password of the named account such as root. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ‘!’ at the beginning of the password)
  • root : Lock and disble root account i.e. re-disabling your root account

A note about root password on an Ubuntu server/desktop

Enabling the root account by setting the password is not needed. Almost everything you need to do as SuperUser (root) of an Ubuntu server can be done using sudo command. For example, restart apache server:
$ sudo systemctl restart apache2
You can add additional user to sudo by typing the following command:
$ sudo adduser sudo
For example, add a user named tom to sudo:
$ sudo adduser tom sudo
You can in as another user say logging as tom from jerry account:
< jerry@nixcraft >$ sudo -i -u tom
When prompted enter jerry’s password i.e. the password being asked for is your own, not tom’s. For more info see “How to create a new sudo user on Ubuntu Linux server” and RootSudo.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

How to Change the root Password in Linux

In today’s tutorial, we will show you how to change the root password in Linux. The root account on a Linux machine is the highest authority account on the system. It has control over everything, can delete and modify anything, and has permission to run any program. Simply put, the root account can do anything that the system supports. Typically, casual users never need to use the root account, while more experienced users need the root account more often, especially if they spend a large amount of their time at a terminal. So, even if you don’t use the root account much, it helps to put a more secure password so that malicious users don’t log into the root account and wreak havoc on your system.

In this tutorial, we will be showing you how to change your root password on various Linux distributions. We will go over the process of changing the root password for Ubuntu, CentOS, Debian, and Fedora. All of these are fairly simple to do, and won’t take much time to complete. Let’s get started.

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.

Table of Contents

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.

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:

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:

How 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:

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!

How 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:

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:

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.

How 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):

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:

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:

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:

You can now reboot your machine either by executing the following command:

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.

If you use one of our Linux VPS hosting services, you can simply ask our technical support via live chat to change your root password on any Linux distribution your server is running on. They are available 24/7 and will change the root password of your Linux machine in less than five minutes.

If you liked this post on how to change the root password on Linux, please share it with your friends via social media. If you have any questions, please leave a comment below – our system administrators will reply to it.

Источник

How to change root password on Debian Linux

How to change root password on Debian Linux

The procedure for changing the password of root is as follows:

  1. First, log in to the Debian Linux server using ssh or console
  2. Open a shell prompt and type the passwd command to change root password in Debian Linux
  3. The actual command to change the password for root on Debian Linux is sudo passwd root

NOTE: Please note that [vivek@debian-linux9:

]$ is my shell prompt. You need to type commands after the $ prompt.

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Debian Linux change root password command

I am going to log in to my Debian Linux 7.x/8.x/9.x server using the ssh command:
ssh vivek@debian-linux9
Once logged in enter the command passwd as follows:
[vivek@debian-linux9:

]$ sudo passwd root
First you need to type the password for vivek user. After that the passwd command asks for the new password, which you will have to enter two times:

Changing root account passwords on a Debian Linux based system

Slightly different procedure for changing passwords in Debian Linux

One can use the following procedure too:
[vivek@debian-linux9:

]$ ssh user@your-centos-server-name-ip
Become a root user via the su command or sudo command:
[vivek@debian-linux9:

]$ sudo -i
OR
[vivek@debian-linux9:

]$ su —
Finally change your root user password:
passwd

Conclusion

This page explained the process for changing the password of root user using the passwd command on a Debian Linux server 9.x. For more info see man page of the passwd command by typing the following man command:
man 5 passwd
man passwd
man 5 shadow

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Читайте также:  Моноблок depo установка windows
Оцените статью