Logo Linux Bash SSH Ubuntu Git Menu
 

AllowUsers - in SSH does not work [closed]

Tags:

ssh

I want to allow logins into my Debian server only from 3 IP addresses.

I added the following line on top of the /etc/ssh/sshd_config file:

AllowUsers = *@IP_ADDRESS_1, *@IP_ADDRESS_2, *@IP_ADDRESS_3  

Restarted SSH:

/etc/init.d/ssh restart

For some reason it does not work. I still can login from any IP address.

Any ideas?

like image 741
user197304 Avatar asked May 04 '26 06:05

user197304


1 Answers

If you want to restrict logins in ssh to certain IP addresses, enable key based logins, disable passwords (optional, but not a bad idea), and in the authorized keys file, you can specify at the beginning of each public key, before the ssh-rsa, the from="" directive will let you use hostnames or IPs with wildcards. This will only allow that key, from that host(s).

The other option is to use /etc/hosts.allow and /etc/hosts.deny, in hosts.deny put

sshd: ALL

in hosts.allow

sshd: <the ips you want to allow>

like image 99
NickW Avatar answered May 06 '26 20:05

NickW