Skip to main content
junior
beginner
Linux

SSH Basics and Key Authentication

Question

How does SSH key authentication work? How do you set it up?

Answer

SSH key authentication uses a public-private key pair. Generate keys with ssh-keygen, copy the public key (~/.ssh/id_rsa.pub) to the server's ~/.ssh/authorized_keys file using ssh-copy-id. The private key stays on your machine and should never be shared. Key auth is more secure than passwords and enables passwordless login.

Why This Matters

SSH is the primary way to access remote servers securely. Understanding key-based authentication is essential for DevOps work, as it's used for server administration, Git operations, CI/CD pipelines, and automated deployments.

Code Examples

Generate and deploy SSH keys

bash

SSH config file for easier access

bash
Common Mistakes
  • Setting wrong permissions on .ssh directory (should be 700) and authorized_keys (should be 600)
  • Sharing or committing private keys to version control
  • Not using a passphrase on private keys
Follow-up Questions
Interviewers often ask these as follow-up questions
  • What's the difference between RSA, ECDSA, and Ed25519 keys?
  • How do you use SSH agent to manage multiple keys?
  • How would you set up SSH tunneling/port forwarding?
Tags
ssh
security
authentication
linux
remote-access