Red Hat Enterprise Linux - Allow Root Login From a Specific IP Address Only

Title: Red Hat Enterprise Linux - Allow Root Login From a Specific IP Address Only
Object Name: mmr_kc-0119626
Document Type: Support Information
Original owner: KCS - Linux
Disclosure level: Public
Version state: final
Environment
FACT:Red Hat Enterprise Linux
Questions/Symptoms
GOAL:Restrict root SSH login to a single IP address
Cause
CAUSE:
Answer/Solution
FIX:This can be accomplished with the use of PAM access controls.  There are two steps:

1. In /etc/pam.d/sshd, add the following line:

account    required     pam_access.so


2. In /etc/security/access.conf, set up root access controls by adding the following two lines at the end of the file:

+ : root : IP_address
- : root : ALL


Replace "IP_address" with the IP address of the system from which root logins will be allowed.  Note that there is a space before and after each colon.  The first line allows root access from the specified IP address; the second line denies root access from everywhere else.  The order of these two lines is significant.  This will take effect immediately with no need to reboot or restart any daemons.


Login attempts that are blocked by this check will be logged in /var/log/secure:

Jul 15 16:51:42 hostname sshd[18241]: fatal: Access denied for user root by PAM account configuration

This method of access control is very flexible and powerful.  For example, if you should need to add a second allowed host at some point in the future, simply add its IP address to the first line:

+ : root : IP_address_1 IP_address_2
- : root : ALL


There are many other options, which are well documented within the access.conf file itself or its reference page.
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Linux ssh Hide OpenSSH Version Banner
Viewed 54831 times since Wed, Apr 22, 2020
RHCS6: Extend an existing Logical Volume / GFS2 filesystem
Viewed 3904 times since Sun, Jun 3, 2018
CONFIGURE FOR ASM Linux
Viewed 6119 times since Sat, Jun 2, 2018
RHCS6: Basic operations on clustered services
Viewed 3225 times since Sun, Jun 3, 2018
Managing temporary files with systemd-tmpfiles on Red Hat Enterprise Linux 7
Viewed 10525 times since Sun, Nov 22, 2020
How to use yum command on CentOS/RHEL
Viewed 11750 times since Wed, Oct 17, 2018
SPRAWDZONA KONFIGURACJA RSYSLOG I LOGROTATE, JAKO ZEWNĘTRZNEGO SERWERA SYSLOG
Viewed 4479 times since Fri, Nov 30, 2018
OpenSSL: Find Out SSL Key Length – Linux Command Line
Viewed 8159 times since Mon, Feb 18, 2019
Tilix: Advanced Tiling Terminal Emulator for Power Users
Viewed 7360 times since Thu, Apr 18, 2019
How to encrypt a partition using LUKS?
Viewed 2419 times since Fri, Jul 13, 2018