What Are SSH Keys and Why Should You Use Them?
SSH (Secure Shell) keys are a pair of cryptographic credentials — a public key and a private key — used to authenticate your identity when connecting to remote servers. Instead of typing a password every time, your keys do the heavy lifting automatically, and far more securely.
SSH keys are widely used by developers, system administrators, and anyone who regularly accesses Linux servers, GitHub, or cloud platforms like AWS and DigitalOcean.
What You'll Need
- A computer running Windows (with Git Bash or WSL), macOS, or Linux
- Access to a remote server or a service like GitHub
- Basic familiarity with the command line
Step 1: Generate Your SSH Key Pair
Open your terminal (or Git Bash on Windows) and run the following command:
ssh-keygen -t ed25519 -C "your_email@example.com"
You'll be asked where to save the key. Press Enter to accept the default location (~/.ssh/id_ed25519). Then, optionally enter a passphrase for an extra layer of security.
Note: If your system doesn't support Ed25519, use -t rsa -b 4096 instead.
Step 2: Add Your Public Key to the Remote Server
Your public key needs to be placed on the server you want to access. Use this command:
ssh-copy-id username@your-server-ip
If ssh-copy-id isn't available (e.g., on macOS without extras), you can manually copy the key:
- Display your public key:
cat ~/.ssh/id_ed25519.pub - Copy the output
- On the server, paste it into
~/.ssh/authorized_keys
Step 3: Test Your Connection
Try connecting to the remote server:
ssh username@your-server-ip
If everything is set up correctly, you'll be logged in without being prompted for a password.
Step 4: Add Your Key to GitHub (Optional)
If you're using SSH with GitHub:
- Copy your public key:
cat ~/.ssh/id_ed25519.pub - Go to GitHub → Settings → SSH and GPG keys
- Click New SSH key, paste the key, and save
- Test with:
ssh -T git@github.com
Troubleshooting Common Issues
- Permission denied: Make sure
~/.sshhas permissions700andauthorized_keyshas600 - Key not recognized: Confirm the correct public key was added to the server
- Multiple keys: Use an
~/.ssh/configfile to manage connections to different hosts
Security Tips
- Always protect your private key — never share it with anyone
- Use a passphrase on your private key for added protection
- Disable password-based SSH login on servers once keys are working
SSH keys are one of the most practical security upgrades you can make to your workflow. Once set up, they're seamless to use and significantly safer than passwords.