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 theroot
user:/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 -t
You might need to run the command as a super user by adding
sudo
to the beginning of the command.
If you are editing the file as aroot
user, you do not need to usesudo
. If you receive a
Permission denied response, use the following command:sudo sshd -t
The 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
ssh
service. It is better to
reload, rather than restart, so you aren’t disconnected from the server. Reload thessh
service with
the following command:service sshd reload
In CentOS 7 and later, you can use the
systemctl reload sshd
command instead of theservice
command to reload SSH. However,service
works in both CentOS and the Ubuntu operating system. -
After the reload completes, use the following command to check that
sshd
is 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 about 1 year ago