How/Syntax to block/deny SSH connection on server – /etc/hosts.deny

SSH is secured shell protocol which is using to connect remotly and securly. We can control the SSH connection to a server by using the following files:

# /etc/hosts.allow
# /etc/hosts.deny

Block an IP address from SSH connection:

sshd : IP-Address

Block more than one IP

sshd : IP-Address1, IP-Address2, IP-Address3

Block IP range:

sshd : 33.*.*.*
sshd : 66.66.*.*

Block all IP addresses from SSH

sshd : ALL



SSH conection result:

[[email protected] ~]# ssh localhost
ssh_exchange_identification: Connection closed by remote host

We can also control the same from /etc/hosts.allow file by adding the keyword ‘DENY’

# vi /etc/hosts.allow
sshd : ALL : DENY

🙂 🙂 🙂

Related Links:
How to manage SSH permission for custom users under your server
How to create a banner/welcome-note for SSH server
How to disable SSH login as root user – PermitRootLogin

Arunlal Ashok

Linux Server Administrator. I'm dealing with Linux servers since 2012. I started this blog to share and discuss my ideas with the world. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

You may also like...

3 Responses

  1. aly says:

    thank u =)

  2. Vishnu Pradeep says:

    [[email protected] ~]# systemctl restart network
    Job for network.service failed. See ‘systemctl status network.service’ and ‘journalctl -xn’ for details.
    [[email protected] ~]#

    Hi Arun,

    I’m getting the above error when i try to restart the network service.

    Could you please guide me to sort this out ?

    OS : Centos-7

Leave a Reply

Your email address will not be published. Required fields are marked *