Linux: Allow SSH Root Login From Specific IP with password

 Allow ssh root logins with password from a single IP address and disable root logins from other IP addresses.

To enable root logins via ssh, PermitRootLogin keyword has to be set to yes in the /etc/ssh/sshd_config (OpenSSH daemon configuration) file. To disable root logins, PermitRootLogin has to be set to no instead.

To allow only certain hosts or IP addresses to ssh as the root user, the Match Address keyword can be used.
The example vim /etc/ssh/sshd_config:

## Global config
PasswordAuthentication no
PermitRootLogin without-password

## Okay allow root login with public ssh key for xx.xx.xxx.xxx ##
Match Address xx.xx.xxx.xxx,xxx.xxx.xxx.xxx
    PasswordAuthentication yes
    PermitRootLogin yes

Restart sshd service:

service sshd restart

The arguments to Match (docs) are one or more criteria-pattern pairs or the single token All which matches all criteria. The available criteria are UserGroupHostLocalAddressLocalPortRDomain, and Address (with RDomain representing the rdomain(4)-(docs) on which the connection was received).







Comments

Popular posts from this blog

Installing the Certbot Let’s Encrypt Client for NGINX on Amazon Linux 2

psql: error: connection to server at "localhost" (127.0.0.1), port 5433 failed: ERROR: failed to authenticate with backend using SCRAM DETAIL: valid password not found

Deploy Nuxt.js app using Apache 2