Establish SSH server access via only a specific IP address

Establish SSH server access via only a specific IP address

Introduction

The purpose of this article is to explain the procedure of manipulating Iptables in order to grant access to a particular server only through a specific IP address. To do this you need to append a rule into the Iptables chain. Follow the article to successfully achieve this.

Login

Step 1: Login to the server that needs to be accesed from a single IP.

# ssh root@xxx.xxx.xxx.xx

Check Iptables rules

Step 2: Check the iptables rules by using the following command

# sudo iptables -S

Step 3: Identify the IP address of the primary server that you want to use to access the server with IP xxx.xxx.xxx.xx. Let this IP be yyy.yyy.yyy.yy.

Addition of new rule

Step 4:To add new rule use the command

# sudo vim /etc/sysconfig/iptables

Press the key I to enter edit mode.

Add the following rule to the Iptables rule of server with IP xxx.xxx.xxx.xx

-A INPUT -m tcp -p tcp -s yyy.yyy.yyy.yy --dport 22 -j ACCEPT

Purpose: This rule will allow access via port 22 only from the IP yyy.yyy.yyy.yy

Step 5: To save, press ESC key followed by :wq! and the hit the ENTER key.

Restart IP tables

Now, restart the Iptables for the changes made, to come into effect:
/etc/init.d/iptables restart

Conclusion

Now the above added rule will only allow ssh access to the server with IP yyy.yyy.yyy.yy and block all other ssh input traffic.

[ht_message mstyle="danger" title="" " show_icon="" id="" class="" style="" ]Make sure to replace xxx.xxx.xxx.xx and yyy.yyy.yyy.yy with your corresponding IP Addresses.[/ht_message]

    • Related Articles

    • How to enable password based authentication for SSH access to server

      IntroductionThis article will provide you with the steps of enabling password-based authentication while logging in to your server through SSH. Before enabling password-based authentication to make sure that you know the password already. If you want ...
    • How to connect via Remote Desktop ( RDC ) to your Window server.

       To manage the Windows installation on your server, you can use Microsoft's Remote Desktop Connection (RDC). Go to your Windows machine,and you will find launch Remote Desktop Connection. There enter your server's IP address. Enter your User Name and ...
    • Set-up SSH keys

      Introduction: Setting up SSH based security to access your server is a much more effective way than the use of a manual root password. Cracking the security system of a VPS depending on SSH keys is nearly impossible since it secures your VPS in a ...
    • Disabling reverse dns lookups in ssh

      Sometimes it is very annoying to wait ten's of seconds to finish remote ssh server's reverse dns lookup procedure. Steps to disable 1. Open configuration file /etc/ssh/sshd_config. 2. Find UseDNS directive and set value to no. 3. In case this ...
    • SSH::Generating a Key Pair for MAC

      Generating SSH keys on Mac OS X The following outlines the process of setting up key-based SSH login on Mac OS X and Mac OS X Server. To set up key-based SSH, you must generate the keys the two computers will use to establish and validate the ...