Home > Operation and Maintenance > Linux Operation and Maintenance > How to enable and disable root account in Ubuntu?

How to enable and disable root account in Ubuntu?

青灯夜游
Release: 2019-03-14 16:04:42
Original
6907 people have browsed it

In Ubuntu Linux, for security reasons, the root account is disabled by default. The following article will show you how to enable and disable the root account in Ubuntu. I hope it will be helpful to you.

How to enable and disable root account in Ubuntu?

Sudo User

Ubuntu users can grant administration to regular users by using a tool called sudo Permissions to perform system administration tasks. Sudo allows granting user permissions: running a program as another user (usually root).

By default, on Ubuntu systems, members of the sudo group are granted sudo access. Because the initial user created by the Ubuntu installer is already a member of the sudo group, the logged-in Sudo user is likely to have administrative rights.

If you want to grant sudo access to other users, simply add the user to the sudo group:

usermod -aG sudo username
Copy after login

To temporarily elevate root user privileges, you need to run the command prefixed with sudo:

sudo some-command
Copy after login

The first time you use sudo in a session, you will be prompted for your user password.

If you want to run commands with sudo permissions without entering a password, you need to edit the sudoers file. To do this, type visudo:

sudo visudo
Copy after login

This will open the /etc/sudoers file using our favorite command line text editor. You need to replace username with a custom username and add the following line to the etc/sudoers file:

username ALL=(ALL) NOPASSWD: ALL
Copy after login

Enable Root account in Ubuntu

If for some reason you need to enable the root account, just set a password for the root user. In Ubuntu and other Linux distributions, you can use the passwd command to set or change the password for a user account.

As an ordinary Ubuntu user, you can only change your own password. We need to have sudo permissions first and then set the root password.

To enable the root account in Ubuntu, you need to run the following command:

sudo passwd root
Copy after login

You will be prompted to enter and confirm the new root password:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Copy after login

Instructions:The password is not displayed on the screen while typing.

In this way, the root account has been successfully enabled in Ubuntu. Now you can use the new password to log in to Ubuntu as the root user.

Note: When setting a password, please make sure to use a strong and complex password. This is good for account security. A good password usually contains at least 16 characters, using at least one uppercase letter, one lowercase letter, one number and one special character.

Disable Root Account in Ubuntu

If you have enabled root user in Ubuntu before and to disable it now, just change the root password Just set it to expire.

Use the following command:

sudo passwd -l root
Copy after login

Recommended related video tutorials: "linux tutorial"

The above is the entire content of this article, I hope it can help Everyone’s learning helps. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to enable and disable root account in Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template