Enable SSH remote root login on CentOS and the Ubuntu operating system
We typically discourage remote root login as a security best practice, but if you need to remotely
Secure Shell (SSH) in to your server as the root user, use the following process for both CentOS®
and the Ubuntu® operating system:
-
Open the following configuration file with your favorite command line text editor, such as
nano
orvim, as therootuser:/etc/ssh/sshd_config -
Find the following line in the file:
#PermitRootLogin no
-
Replace the commented-out line with the following line:
PermitRootLogin yes
-
Save and close your text editor.
-
Test your change to ensure that your SSH configuration does not break when you reload the
ssh
service. Check the syntax with the following command:sshd -tYou might need to run the command as a super user by adding
sudoto the beginning of the command.
If you are editing the file as arootuser, you do not need to usesudo. If you receive a
Permission denied response, use the following command:sudo sshd -tThe server gives no response if the syntax is correct. You should see a response similar to the following:
[root@testserver ~]# sshd -t [root@testserver ~]# -
After you verify the syntax for your SSH configuration file, reload the
sshservice. It is better to
reload, rather than restart, so you aren’t disconnected from the server. Reload thesshservice with
the following command:service sshd reloadIn CentOS 7 and later, you can use the
systemctl reload sshdcommand instead of theservice
command to reload SSH. However,serviceworks in both CentOS and the Ubuntu operating system. -
After the reload completes, use the following command to check that
sshdis running:service sshd status
The response should indicate that the service is currently running. You can now SSH into the server as
the root user.
Note: Most bad actors attempt to hack into a server as the root user, so Rackspace recommends
disabling the ability to log in as root remotely. Instead, Rackspace recommends that you use SSH to
access the server as a user with sudo privileges. Then, you can elevate to the root user after you
connect.
Updated almost 2 years ago
