How to Restrict SSH login to a Specific IP or host in Ubuntu?
Step1. Login to the server with SSH access.
![](https://support.gmoace.com/wp-content/uploads/2024/01/1-6.png)
Step2. Login to the server with root access.
![](https://support.gmoace.com/wp-content/uploads/2024/01/2-6.png)
Step3. Open file /etc/hosts.deny by using a text editor.
# vi /etc/hosts.deny
Step4. Add the following line to deny all incoming SSH connections to the server:
# sshd: ALL
Step5. Save and close the file.
![](https://support.gmoace.com/wp-content/uploads/2024/01/3-6.png)
Step6. Open the file /etc/hosts.allow file by using a text editor:
# vi /etc/hosts.allow
Add the following line to allow incoming SSH connections for specific ip or host to the server.
sshd : localhost
sshd : 192.168.0.
sshd : 99.151.250.7
Step7. Save and close the file.
![](https://support.gmoace.com/wp-content/uploads/2024/01/4-3.png)
You can allow or deny based on IP address, subnet, or hostname.
Thank you!!!