SSH cut off access to those you do not want

You want to cut it SSH σε ένα διακομιστή Linux; Εάν είστε διαχειριστής Linux, θα γνωρίζετε την χρησιμότητα μιας σύνδεσης SSH που σας επιτρέπει να έχετε λειτουργίες on remote systems.

Due to the importance of the function, it is very likely that you have already taken many steps to lock SSH access. Using an SSH key for authentication instead of a simple one , και η αλλαγή της default SSH θύρας (22), μπορεί να είναι τα πρώτα βήματα που χρειάζεται να κάνετε, αλλά δεν είναι αρκετά.

Below we will see one more step you can take. It is so easy and obvious that most managers forget that it exists as an option. This step does not require third-party software and can be configured in seconds.

What you will need

  • A Linux server running SSH daemon
  • The IP addresses of each client that needs access to the server

You should also have access to of the remote server, in case something goes wrong and you get locked out, like any time you tamper with SSH.

The first thing we need to do is allow the IP address of any client that needs SSH access to the remote server. Once you have a list of IP addresses, you can add them to /etc/hosts.allow. To do this, run the command:


Enter the root password, and

nano /etc/hosts.allow

At the bottom of this file, add the following:

sshd: IP

Where IP is the IP address of the remote client that needs access to the server. If you have multiple IP addresses, you can enter them as follows:


Or something like this:

sshd: [::1]

Save and close the file. Nano storage is done by typing CTRL + X together, then y, and Enter

How to block all other addresses

Now that we have allowed an IP address or a list of addresses, it is time to block all other addresses. One thing to know is that a Linux system first reads the hosts.allow file (top to bottom) and then the hosts.deny (top to bottom). Thus, an attempt to connect SSH from an IP address in hosts.allow will be allowed, although hosts.deny may block all IPs.

So, to block all other IP addresses, open the required file with the command:

nano /etc/hosts.deny

At the bottom of this file, add the following:

sshd: ALL The Best Technology Site in Greecefgns

Subscribe to Blog by Email

Subscribe to this blog and receive notifications of new posts by email.

Written by giorgos

George still wonders what he's doing here ...

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).