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
FACT:Red Hat Enterprise Linux
GOAL:Restrict root SSH login to a single IP address
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

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
There are no attachments for this article.
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
WatchDog script for checking server running
Viewed 2611 times since Tue, Jul 31, 2018
Get UUID of Hard Disks [Update]
Viewed 1062 times since Tue, Jul 17, 2018
Linux nslookup Command Examples for DNS Lookup
Viewed 1079 times since Sat, Sep 29, 2018
RHEL: Scan and configure new SAN (fibre channel) LUNs
Viewed 4924 times since Sun, May 27, 2018
Extending Linux LVM partitions script
Viewed 733 times since Wed, Feb 6, 2019
HowTo: Send Email from an SMTP Server using the Command Line
Viewed 707 times since Mon, Feb 18, 2019
RHCS6: Mirror/unmirror a GFS2 volume
Viewed 964 times since Sun, Jun 3, 2018
RHEL: GPT/MBR partition tables (using disks larger than 2 TiB)
Viewed 1754 times since Sun, May 27, 2018
Top 20 OpenSSH Server Best Security Practices - good article
Viewed 901 times since Mon, Oct 1, 2018
RHCS6: Quorum disk and heuristics
Viewed 1831 times since Sun, Jun 3, 2018