by stephen-mw · 11y ago · 0 comments
1. Disable password authentication altogether
2. Create and use keypairs
3. Add an "AllowUsers foo" line to /etc/ssh/sshd_config so that only your user is allowed to SSH
4. Install sshguard or fail2ban and set the ban limit to a week
There are other things you can do, but I find this to be the lowest hanging fruit for the best security.
* Arch Linux (openssh-6.9p1-1): #PermitRootLogin no
* CentOS 7 (openssh-server 6.6.1p1-12.el7_1): #PermitRootLogin yes
* Debian 8.1 (openssh-server 1:6.7p1-5): PermitRootLogin without-password
* Fedora 22 (openssh-server 6.9p1-2.fc22): #PermitRootLogin yes
* openSUSE 13.2 (openssh 6.6p1-5.1.3): #PermitRootLogin yes
* Ubuntu 14.04.2 (openssh-server 1:6.6p1-2ubuntu1): PermitRootLogin without-password
* Ubuntu 15.04 (openssh-server 1:6.7p1-5ubuntu1): PermitRootLogin without-passwordI looked into OpenSSH's commit history ([2],[3],[4],[5]) and it looks like some waffling and/or release-process side-effects resulted in the man page in 6.9 saying the default is "no", but the actual code retaining "yes" (confirmed in the portable 6.9p1 tarball). I kind of hope I'm wrong somehow; this is a bit disturbing.
[1] http://www.openssh.com/txt/release-6.9 [2] https://github.com/openssh/openssh-portable/commit/88a7c598a... [3] https://github.com/openssh/openssh-portable/commit/d921082ed... [4] https://github.com/openssh/openssh-portable/commit/47aa7a0f8... [5] https://github.com/openssh/openssh-portable/commit/7de4b03a6...
During the years I've found that changing the port to something like 7865 decreases login attempts up to 100%. Personally it's always the first thing I do along with changing LoginGraceTime to 5s
You probably also want to set kex, ciphers and MAC preferences in your client config for when you connect to servers with suboptimal settings.
Personally, I have also moved away from RSA keys and prefer using Ed25519 ones instead.
I ask because I administer about 300 servers with DenyHost grandfathered on the servers. I've googled a bit to see the relative merits and DH is just for ssh whereas fail2ban is more general.
I somehow didn't know about sshguard - it looks interesting (and also seems to do more than just ssh brute force blocking).
So... do I need to take DH off the herd and replace?