I have a monitoring server that requires the SSH connection details of a non-sudo user account of each box it monitors. Is there a way that I can configure a specific user account such that it can only be logged into from a specific IP (or better yet hostname)? I do not want to restrict the ability of other users on the server to be able to connect from other addresses (otherwise I'd just use a firewall), or use password authentication for the monitoring service only.
See
man sshd_config
. There is possibility to addAllowUsers
block where you can specify both user and host like this:Of course you need to specify also other users you want to allow login from, if you have some.
Another solution (depends on bug fixes!)
As I think about it once more, there is possibility to modify your
sshd_config
like this:This would easily block all users except from
user
fromhostname
and from everywhere else it would blockuser
.BUT it doesn't work, because of few bugs reported upstream [1] [2]. But we got it promised it will get fixed in next release.
You can use wildcards for the AllowUsers line on the
/etc/ssh/sshd_config
file. So it would be feasible to add the line:Or:
To allow everyone from that IP address or hostname access.
Remember to:
Once you've made the changes, so long as you're on a version before 15.04. 15.04 uses systemd now, so has a different mechanism for controlling services.
According to man pages, this should work:
I tested this on Debian and it seemed to work correctly.
Since this is the top search result in google, I think people should also be aware of setting permissions in the
/etc/hosts.allow
file (curtesy of Cameron Oltmann's blog post on the matter):And you should be able to use
user@address
in this file, per this lifewire.com link: