I want to block a ssh connection from particular IP address. for example: my system IP address is,another two system is and, I want to block the ssh connection for 8.12, but I want to login from and etc..

How can I do this?


The simplest and best solution would be "Using whatever firewall you happen to be using". Just block access to port 22 from (or specifically only allow it from

If you don't currently have a firewall setup, then you may want to look into iptables, which comes as part of the linux kernel. There's a tutorial here. There's also quite a few GUI interfaces for it.

The specific command you want to do what you've described above is:

# iptables -A INPUT -p tcp --dport ssh -s -j DROP

This adds a rule to INPUT for TCP traffic aimed at your ssh port (22), that is coming from, and drops it.


If you have tcpwrappers installed, then you can put an entry in to hosts.deny. Read the man page for hosts.deny for details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy