Root User in Ubuntu- Important Things You Should Know

Техника

Unlike many distributions like Fedora, in Ubuntu, you are not given any option to set a root password during installation.

But if you want, you can set the password for the root account.

sudo su
use root account without setting up the root password in Ubuntu using sudo

Still want to set a separate password for the root? Let me show how to do that.

It’s a good idea to change your passwords regularly and consider using enterprise password management software.

This guide will help you change your Linux root password in Ubuntu or CentOS, or reset the password.

restart or change root password in linux
  • A computer running Linux
  • Command-line interface (terminal)

ROOT-пользователь — это пользователь с правами администратора, созданный по умолчанию в Linux-системе (Ubuntu). Root аналог администратору в ОС Windows, который имеет доступ ко всему в системе.

Этот способ предполагает вход в систему Ubuntu под пользователем с sudo правами, а команда «su» разрешена как часть «sudo» привилегий.

sudo su

Глядя на скриншот выше, можно заметить смену пользователя на «root», таким образом, мы вошли в Ubuntu под root, используя свой пароль.

Теперь мы можем сменить пароль root-пользователя, для этого необходимо использовать следующую команду:

passwd

После ввода команды указываем новый пароль в запросе «New password» и повторяем новый пароль после запроса «Retype new password».

Пароль для root будет установлен при первом использовании команды или изменит его на новый пароль при дальнейших использованиях команды «passwd».

А работает ли новый пароль? Давайте это выясним, нажимаем сочетание клавиш «Ctrl+D», чтобы окончить текущий ввод данных в терминале, либо запускаем новый терминал и вводим новую команду:

su

Данной командой мы войдем в систему как root, после чего вводим новый пароль, который мы только что установили для root.

Таким образом мы успешно изменили пароль от root.


Are you looking to change the root password in Ubuntu?

Changing passwords is a good practice and should be done periodically.

There are three (3) ways to change passwords in Ubuntu.

The first two (2) options use the command line, and the other uses Linux’s graphical interface (GUI).

  • Ubuntu installed and running
  • A user with sudo privileges
  • Access to a terminal/command line
  • The apt-get tool, pre-loaded in Ubuntu and other Debian-based distros
Содержание
  1. Option 1: Changing Ubuntu Password in the Command Line
  2. Option 2: Change sudo Password with the passwd Command
  3. Option 3: Changing Ubuntu Password Using GUI
  4. 1: How to enable Ubuntu root Login Temporarily?
  5. 2: How to enable root user in ubuntu via Graphical User Interface?
  6. 3: How to enable ubuntu root in Command-line?
  7. Conclusion
  8. What is root user? Why is it locked in Ubuntu?
  9. How to run commands as root user in Ubuntu?
  10. How to become root user in Ubuntu?
  11. How to enable root user in Ubuntu?
  12. How to change Ubuntu root password?
  13. How to change the Ubuntu default password using the command line?
  14. How to change default root password Ubuntu using GUI?
  15. How to reset the default ubuntu password ?
  16. How to reset Ubuntu’s root password from Recovery Mode
  17. How to switch a root user account in Ubuntu
  18. Sudo Users
  19. What are Ubuntu default login credentials?
  20. What is the Ubuntu Default Root Password?
  21. How to enable root account in Ubuntu?
  22. How to disable your root user account in Ubuntu?
  23. Advantages and Disadvantages of Ubuntu
  24. Conclusion 
  25. Changing the Root Password in CentOS
  26. Step 1: Access the Command Line (Terminal)
  27. Step 2: Change the Password
  28. Step 1: Access Boot Menu
  29. Step 2: Edit Boot Options
  30. Step 3: Remount the Drive
  31. Step 4: Changing the Password
  32. Step 5: Restart
  33. Сбрасываем пароль от root через GRUB
  34. How to set a root password in Ubuntu
  35. How to disable root account in Ubuntu
  36. Changing Your Root Password in Ubuntu
  37. Step 1: Open a Terminal Window
  38. Step 2: Change Your Root Password
  39. Resetting a Root Password in Ubuntu
  40. Step 1: Boot to Recovery Mode
  41. Step 2: Drop Out to Root Shell
  42. Step 3: Remount the File System with Write-Permissions
  43. Step 4: Change the Password
  44. You can lock users too! Here’s how to do it

Option 1: Changing Ubuntu Password in the Command Line

To change the sudo password using the sudo command:

1. First, open the terminal using the keyboard shortcut CTRL+ALT+T.

2. Query for a password change by running the command:

sudo passwd root

You will be prompted to enter and verify a new password. The output will inform you the password was updated successfully.

example output after ubuntu changing root password
image of terminal to exit changes after password reset

Option 2: Change sudo Password with the passwd Command

1. First, open the terminal (CTRL+ALT+T).

sudo –i

Type in your current password and hit Enter. The output you receive should show that you can now run commands as root.

example command for sudo -l

3. Next, change the password by running the command:

passwd

Type and retype a new password to verify the change.

exit

5. Exit out of the terminal with the same command:

exit

Option 3: Changing Ubuntu Password Using GUI

To change the default root password in Ubuntu without using the terminal or any commands, use the graphical interface.

1. Open the Activities overview by pressing the Windows or Super key.

2. Type settings in the search bar and click on the Settings icon.

3. In Settings, click on the Details card (which is most likely the last one).

example of Ubuntu graphical interface with details selected

5. This will open a new Change Password pop-up. Type in your current root password, your new root password and verify the new password by retyping it.

6. Once you have filled in all the fields, click Change to confirm the changes.

change password prompt in ubuntu

Finally, make sure that your password includes both lower and upper case letters, numbers and special characters. It is essential to have a strong password to prevent brute force attacks.

How to Enable Root Account in Ubuntu? [Ubuntu Root Login]

List of content you will read in this article:

If you are a newbie, you may be scratching your head about how to enable your root account in Ubuntu! Well, for several security purposes, the ubuntu root login account is kept disabled. Before we begin, here is some preface. 

When you install Ubuntu, a root account is created. The issue here is that you do not have the provision to set the password for the account. 

Дополнительно:  Как сделать root права на poco x3 pro

sudo grep root /etc/passwd

The x in the output signifies that the account’s password is empty.

sudo grep root /etc/shadow

  • Temporary Method
  • Command-Line and Graphical User Interface Method
  • Command-Line Method

1: How to enable Ubuntu root Login Temporarily?

2: How to enable root user in ubuntu via Graphical User Interface?

Type root in the first textbox.

Type your root account password.

As soon as you type the password, you encounter an error message. The reason is that a security layer in the graphical interface stops any login until and unless several other configuration files are configured. 

sudo cp /etc/gdm3/custom.conf /etc/gdm3/custom.conf_backup

sudo cp /etc/pam.d/gdm-password /etc/pam.d/gdm-password_backup

Now, simply, open the “/etc/gdm3/custom.conf” configuration file

sudo vi /etc/gdm3/custom.conf

Press save and exit. 

Now, open “/etc/pam.d/gdm-password” which is a configuration file.

Just save and hit exit on the ‘gdm’ configuration file.

sudo reboot -f

As you have rebooted your system, login into the root account now.

You can log in to the root account easily. 

sudo passwd -dl root

Reverse whatever changes you made in the two configuration files earlier. 

Delete “AllowRoot=true” from the “/etc/gdm3/custom.conf” configuration file as shown below.

Next, delete the ‘#’ from  “/etc/pam.d/gdm-password”.

And you are done!

3: How to enable ubuntu root in Command-line?

Using the command-line method, you can easily enable or disable the root account through the command line. Here, you cannot log in through a graphical interface.

sudo -i passwd root

su – root

sudo passwd -dl root

To be sure, switch to the root account and see if the process is successful.

su - root

If you see the same message as the above image, then yes, you have successfully disabled the account, as now you can see that the authentication has failed. 

Conclusion

We hope that the article solved your queries and provided you with a better understanding of the topic. If you have any questions or suggestions, please leave them in the comment section below.

People are also reading:

Either you run commands with root privilege like this:

sudo any_command
sudo su

What is root user? Why is it locked in Ubuntu?

Root User Ubuntu

You don’t need to have root privilege for your daily tasks like moving file in your home directory, downloading files from internet, creating documents etc.

Take this analogy for understanding it better. If you have to cut a fruit, you use a kitchen knife. If you have to cut down a tree, you have to use a saw. Now, you may use the saw to cut fruits but that’s not wise, is it?

Does this mean that you cannot be root in Ubuntu or use the system with root privileges? No, you can still have root access with the help of ‘sudo’ (explained in the next section).

How to run commands as root user in Ubuntu?

apt update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)

So, how do you run commands as root? The simple answer is to add sudo before the commands that require to be run as root.

sudo apt update
[email protected]:~$ sudo apt update
[sudo] password for abhishek: 

If you are absolutely new to Linux, you might be surprised that when you start typing your password in the terminal, nothing happens on the screen. This is perfectly normal because as the default security feature, nothing is displayed on the screen. Not even the asterisks (*). You type your password and press enter.

Bottom line:
To run commands as root in Ubuntu, add sudo before the command.
When asked for password, enter your account’s password.
When you type the password on the screen, nothing is visible. Just keep on typing the password and press enter.

How to become root user in Ubuntu?

The sudo command allows you to simulate a root login shell with this command:

sudo -i
[email protected]:~$ sudo -i
[sudo] password for abhishek: 
[email protected]:~# whoami
root
[email protected]:~# 

You’ll notice that when you switch to root, the shell command prompt changes from $ (dollar key sign) to # (pound key sign). This makes me crack a (lame) joke that pound is stronger than dollar.

sudo su

If you try to use the su command without sudo, you’ll encounter ‘su authentication failure’ error.

exit

How to enable root user in Ubuntu?

sudo passwd root

Again, this is not recommended and I won’t encourage you to do that on your desktop. If you forgot it, you won’t be able to change the root password in Ubuntu again.

sudo passwd -dl root

I hope you have a slightly better understanding of the root concept now. If you still have some confusion and questions about it, please let me know in the comments. I’ll try to answer your questions and might update the article as well.

Ubuntu Default Root Password? [Change Ubuntu Password]

List of content you will read in this article:

How to change Ubuntu root password?

  1. Open the terminal by pressing Ctrl+Alt+T or searching for «Terminal» in the Ubuntu Dash.
  2. Type the command «sudo passwd root» and press Enter. You will be prompted to enter your current user password.
  3. After authenticating, you can set a new password for the root user. Make sure to choose a strong and secure password.
  4. Retype the new password when prompted to confirm.
  5. Once the password change is successful, you can exit the terminal.

How to change the Ubuntu default password using the command line?

  1. Launch the terminal by pressing Ctrl+Alt+T or searching for «Terminal» in the applications menu.
  2. To change the root password, you need administrative privileges. Execute the following command to access root privileges: sudo -i
  3. Once you have root privileges, enter the following command to change the root password: passwd

You will be prompted to enter a new password. Make sure to choose a strong and secure password that includes a combination of uppercase and lowercase letters, numbers, and special characters. Note that the password will not be visible as you type.

  1. After entering the new password, you will be prompted to confirm it. Re-enter the password carefully, ensuring it matches exactly as you intended.
  2. If the password change is successful, you will receive a confirmation message. Your Ubuntu system’s root password is now updated.
Дополнительно:  Root init что это

Remember to keep your root password confidential and avoid using easily guessable information. Regularly changing your passwords enhances the overall security of your Ubuntu system.

How to change default root password Ubuntu using GUI?

  1. Launch the Terminal: Open the Terminal by clicking on the Applications menu, typing «Terminal» in the search bar, and selecting the Terminal application.
  2. Access User Accounts: Type «sudo gnome-control-center user-accounts» command in the Terminal and press Enter. This command will open the User Accounts settings.
  3. Authenticate: Enter your user password when prompted to authenticate your access.
  4. Modify Root Account: In the User Accounts settings, select the » root » account and click the «Password» button.
  5. Set New Password: Enter the new password for the root account in the provided fields. Make sure to choose a strong and secure password.
  6. Apply Changes: Click on the «Change» or «Apply» button to save your changes to the root password.
  7. Confirm Changes: Close the User Accounts settings and log out of your session. To apply the new root password, you need to log back in using the updated credentials.

Remember, changing the root password in Ubuntu enhances the overall security of your system by preventing unauthorized access. Ensure you choose a unique and robust password to maintain the integrity of your Ubuntu installation.

How to reset the default ubuntu password?

Forgot your Ubuntu login password? If you haven’t used Ubuntu for a long time, and now you want to login in, and you don’t remember your password. So here is the method to reset your Ubuntu Password. You quickly get your password, and you don’t even need to reinstall it.

How to reset or change root password:

Open up the terminal!

After opening the terminal, type the command sudo space passwd space root

  • [ Sudo passwd root ] & press enter
  • Enter the new root password and press Enter button
  • Retype root password and enter
  • Password changed successfully

To verify your new password, use this command.

  • su root  & press Enter key 
  • Now Enter the new given password of your Ubuntu and press Enter Key

Now you can use your new Ubuntu Root Password. You have successfully made a new password to the Ubuntu root terminal.

How to reset Ubuntu’s root password from Recovery Mode

  1. Start or restart your Ubuntu system.
  2. When the GRUB boot menu appears, select the advanced options for Ubuntu and choose the recovery mode option. If you don’t see the GRUB boot menu, you may need to press and hold the Shift key during startup to make it appear.
  3. In the recovery mode menu, select the option that says «root Drop to root shell prompt.» This will drop you into a root shell with root privileges.
  4. Remount the file system in read/write mode by running the following command:

mount -o remount,rw /

  1. Next, you need to change the root password. Use the following command to set a new password:

You will be prompted to enter the new password twice. Note that when you type the password, it won’t be visible on the screen for security reasons. Press Enter once you’ve entered the new password.

  1. After setting the new password, you can reboot your system by running:

Remember to keep the root password secure and make sure to remember it or store it in a safe place.

How to switch a root user account in Ubuntu

Sudo Users

The first time you use Sudo, you will be prompted to enter the password. If you want to run the command with sudo without entering the password, you must edit the sudoers file.

What are Ubuntu default login credentials?

What is the Ubuntu Default Root Password?

How to enable root account in Ubuntu?

1. Open a terminal: Press `Ctrl + Alt + T` on your keyboard to open a terminal window.

sudo passwd root

4. Next, you will be asked to enter the new password for the root account. Type your desired password and press Enter. Please note that while typing the password, no characters will be displayed on the screen for security reasons.

5. Confirm the new password by typing it again and pressing Enter.

How to disable your root user account in Ubuntu?

  1. Open a terminal on your Ubuntu system.
  2. Run the following command to set a password for the root account (if you haven’t already done so): sudo passwd root

You will be prompted to enter and confirm a new password for the root account.

  1. Once the root password is set, run the following command to lock the root account: sudo passwd -l root

This command locks the root account, effectively disabling it.

Advantages and Disadvantages of Ubuntu

Here you can find the pros and cons of using Ubuntu leaving root logins disabled by default, includes:

  • People often forget their login passwords occasionally (the root password).
  • It avoids the access of «I can do anything» login by default. It will prompt for a password earlier; the changes can happen!
  • Sudo adds a log access of the command(s) run (in /var/log/auth.log). In case you were in trouble, you can go to the authorities and run.
  • Every cracker trying to brute-force their manner in on a server will know it has an account named root and could try that first.
  • What they do not know is the usernames of your other users. Due to the fact that the root account password is locked, this attack doesn’t pose any threat at all as there may be no password to crack or guess inside the first location.
  • Allows easy transfer of admin rights by adding or removing users. When you use only one Ubuntu root password, you could change the root password if you forgot.
  • Sudo may be set up with a safety policy.
Дополнительно:  Windows не удалось подключиться к Wi-Fi сети. Решение ошибки в Windows 7

Automatically the authentication expires after some time (you can also set the time duration). So if you walk away or leave your desktop a few times from the terminal after running commands as root using sudo, you will not be leaving a root terminal open indefinitely.

Conclusion 

You can also add special characters to your password. Add up to at least 16 characters with upper, and lowercase letters and numbers. It is how we can change the default root password.

Changing the Root Password in CentOS

Changing a password in CentOS is almost identical to changing it in Ubuntu.

Step 1: Access the Command Line (Terminal)

Right-click the desktop, then left-click Open in Terminal.  Or, click Menu > Applications > Utilities > Terminal.

Step 2: Change the Password

sudo passwd root
change root password in centos

This is a similar process as in Ubuntu, with a couple of variations.

Step 1: Access Boot Menu

Restart the system, then tap the Esc key about once per second to launch the GRUB menu.

Step 2: Edit Boot Options

Use the arrows to highlight the version of Linux you boot into, then press e.

Use the arrows to highlight the line that starts with kernel or Linux.

Step 3: Remount the Drive

mount / -o remount,rw

Step 4: Changing the Password

passwd

Press Enter, and the system should prompt you to enter and confirm a new password.

Step 5: Restart

mount / -o remount,ro
sync
reboot

Your system should restart. Confirm that your new password works by logging in.

Note: If you ever come across a Linux boot failure, be sure to save our guide on using GRUB rescue to troubleshoot it.

It can be more challenging if you’ve lost or forgotten a password, but with a little creative restarting and editing, you shouldn’t find it too hard.

Сбрасываем пароль от root через GRUB

Существует еще один способ для изменения пароля от root или любого другого пользователя при загрузке Ubuntu.

Сначала перезагружаем наш ПК. Если меню GRUB не появляется автоматически, то удерживаем клавишу «Shift» во время загрузки. Это принудительно откроет меню GRUB.

Затем выбираем пункт «Ubuntu» в меню и нажмите клавишу «E», чтобы начать редактирование конфигурации загрузки.

Далее необходимо внести изменения в строку, заменяем значение:

quiet splash $vt_handoff
rw init=/bin/bash

Результат отображен на скриншоте ниже:

Изменения заключаются в том, чтобы из GUI перейти в оболочку Bash для внесения изменений — смена пароля. Нажимаем клавишу «F10», чтобы загрузиться с новой конфигурацией.

Загрузка с измененной конфигурацией сработает только один раз и сброситься при повторной загрузке.

Мы вошли в систему как root-пользователь в командной строке. Теперь используем команду для сброса пароля:

passwd

Указываем и повторяем новый пароль.

Затем перезагружаем систему в обычном режиме (без GRUB) и входим как root уже с новым паролем.

How to set a root password in Ubuntu

Make sure you use different passwords for the root account and sudo as using the same will be a security threat!

sudo passwd root

Let’s breakdown the command:

  • sudo: To execute command with superuser privileges
  • passwd: Used to change passwords for user accounts
  • root: Indicates a root account

Once you execute the above command, it will ask you to enter your new password:

setup root password in Ubuntu
su
login as a root in Ubuntu
exit

How to disable root account in Ubuntu

I would advise you to disable the root account as you can achieve everything with sudo (which I mentioned at the beginning of this guide).

Or you no longer want to have a root account enabled. And in all cases, it can be disabled as it was by default easily.

sudo passwd -dl root

This command will delete the existing root password and lock the root account (don’t worry, it can be enabled again by the above method).

Once you execute the above command, you can no longer use the root account:

disable root account in Ubuntu

Changing Your Root Password in Ubuntu

Step 1: Open a Terminal Window

Right-click the desktop, then left-click Open in terminal.

Alternately, you can click Menu > Applications > Accessories > Terminal.

Step 2: Change Your Root Password

sudo passwd root

The system will prompt you to enter your password – this is the same password you use to log in to the system.

Next, the system will prompt you to enter a new password. Do so, and then re-enter it exactly the same when the system prompts you to retype the password. This double-entry confirms that you have typed the password correctly.

change root password in ubuntu terminal command

Resetting a Root Password in Ubuntu

In some situations, you may need to access an account for which you’ve lost or forgotten a password.

Step 1: Boot to Recovery Mode

Restart your system. Once you see the splash screen for the computer manufacturer, hold down the shift key. The system should come up with a black and white GRUB, or boot menu, with different Linux kernel versions displayed.

Step 2: Drop Out to Root Shell

The system should display a menu with different boot options. Use the arrow keys to navigate to the option labeled root and press Enter.

The system should respond by giving you a command-line interface with a prompt.

Step 3: Remount the File System with Write-Permissions

Right now, your system only has read-only access to your system. That means it can look at the data, but cannot make any changes. But we need write-access to change the password, so we’ll need to remount the drive with the appropriate permissions.

At the prompt, type:

mount –o rw,remount /

Press Enter. This should allow you to make changes to the data on the hard drive.

Step 4: Change the Password

At the prompt, type:

passwd username
shutdown –r

Hit Enter, and your system should restart. Don’t press any keys, let the system come up to the login screen, and test to make sure the new password works.

Note: Learn how to use the chpasswd command. Chpasswd is helpful for managing multiple passwords and making multiple changes.

You can lock users too! Here’s how to do it

I hope you will find this helpful.


Subscribe

Join the newsletter to get the latest updates.

Great! Check your inbox and click the link

Please enter a valid email address!


Оцените статью
Master Hi-technology
Добавить комментарий