How to Enable and Disable Root Login in Ubuntu

1. How to Enable Root Account in Ubuntu?

To Access/Enable the root user account run the following command and enter the password you set initially for your user (sudo user).

$ sudo -i 
Enable Root Access in Ubuntu

2. How to Change Root Password in Ubuntu?

You can change root password with sudo passwd root command as shown below.

$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Change Root Password in Ubuntu

3. How to Disable Root Access in Ubuntu?

If you wish to disable root account login, run the command below to set the password to expire.

$ sudo passwd -l root
Disable Root Access in Ubuntu

4. How to enable ssh root access in Ubuntu?

Login to your server as root.

As the root user, edit the sshd_config file found in /etc/ssh/sshd_config:

vim /etc/ssh/sshd_config

Add the following line to the file, you can add it anywhere but it’s good practice to find the block about authentication and add it there.

PermitRootLogin yes

Save and exit the file.

Restart the SSH server:

systemctl restart sshd

or

service sshd restart

And that’s it! With the new line added and the SSH server restarted, you can now connect via the root user.

In this instance, you are going to be able to login as the root user utilizing either the password or an ssh key.

When using SSH Keys, you can set the PermitRootLogin value to `without-password` instead of yes. To accomplish this, simply modify the following information noted in step 2 above instead:

PermitRootLogin without-password

This process should work on almost any version of Linux server that the sshd service is installed. If you are using a cPanel server though you can easily control this setting from the WHM interface. In these cases, it’s recommended to modify this setting from your control panel interface.

赞(0)
未经允许不得转载:PHPez » How to Enable and Disable Root Login in Ubuntu

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址