Question

SSH - Two-factor or Key pairs?

Anyone who has an opinion on which method is the best to protect SSH, keypairs or the two factor authentication below?

https://www.digitalocean.com/community/articles/how-to-protect-ssh-with-two-factor-authentication

To protecting houses we first had private keys and public keyholes. Then door codes. Then access cards combined with a code. I mean when I lose my key I also lose access to my server and someone else might get access instead. Even if I protect my private key with a password it’s easy to hack on someone’s computer if it gets lost. If I store a password on a server It’s not so easy to hack it if I have fail2ban and port knocking.

Keys always need to be stored somewhere, unencrypted discs, smartphones, dropbox etc. An easy-to-remember 18+ character password only need to be stored in a non-hackable brain. And combined with two factor authentication it seems to me safer then using key pairs.

If I use the Google Authenticator app in my phone I can still lose my phone/sim card. But if I also enable two-factor for a second phone I can always store that sim card in a safe place to always have access to my server, just in case I lose my phone. And if anyone get access to my phone they still need to know the ssh password.

Anyone who has an opinion on this?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@sim thanks for the info on badips.com. Hopefully this’ll reduce the number of fail2ban emails I get on a daily basis.

We have both, normally we use keys and in case that it’s an emergency or the like, we can log in with 2FA. <br> <br>Additionally we have fail2ban and synchronize our block list over all our servers with badips.com. <br> <br>

2FA Works Great, make sure you backup your private keys in a safe place though incase you loose or break your phone. <br> <br>2factor is great because your phone can be offline and only you can access it if you have that phone or super long pin. <br> <br>What I dont like about keys is that they have to be stored on a computer and are hard to backup if you loose them. <br> <br>Johnathan Martin <br>fitbobcat.com