Tired of typing passwords every time you log into a server via SSH? Passwordless SSH authentication using SSH keys is the way to go. It’s secure, efficient, and saves you time. In this guide, I’ll walk you through setting it up in just 5 minutes. Let’s dive in!
Prerequisites
- Two machines: One to act as the client (your local machine) and another as the server (remote machine).
- SSH installed on both devices (most Linux/macOS systems have it pre-installed).
- Basic Linux/macOS command-line knowledge.
Step 1: Generate an SSH Key Pair on Your Client
Open your terminal and run:
ssh-keygen -t rsa -b 4096
- Press Enter to accept the default file location (
~/.ssh/id_rsa). - You can skip setting a passphrase for simplicity, but it’s recommended for added security.
This creates two files:
-
~/.ssh/id_rsa: Your private key (keep this secret). -
~/.ssh/id_rsa.pub: Your public key (this will be placed on the server).
Step 2: Copy the Public Key to the Server
Use the ssh-copy-id command to install your public key on the server:
ssh-copy-id user@server_ip
- Replace
userwith your server username (e.g.,ubuntu,root). - Replace
server_ipwith the server’s IP address or hostname.
You’ll be prompted to enter your server’s password once, after which your public key is copied to ~/.ssh/authorized_keys on the server.
Step 3: Test Passwordless Login
Try logging in to verify it works:
ssh user@server_ip
- If successful, you’ll be connected to the server without a password prompt!
Troubleshooting
If you still need a password, check these common issues:
-
Permissions: Ensure your client’s
~/.sshfolder is700and the private key (id_rsa) is600. -
Server-side config: Verify
PubkeyAuthentication yesis enabled in~/.ssh/authorized_keyson the server. - Firewall: Ensure port 22 (default SSH port) is open on the server.
Bonus: Secure Your Private Key
- Protect the private key (
id_rsa) with a passphrase (openssl can help reset one if needed). - Store it securely—never share it or commit it to public repositories.
Conclusion
In under 5 minutes, you’ve eliminated passwords from your SSH workflow! This method is widely used in DevOps, cloud servers, and automation pipelines. Just remember to keep your private key safe and rotate it periodically if compromised.
Got questions? Drop them below! Happy hacking! 🚀
Related Tags: SSH, Linux, Security, DevOps, Cloud, Automation
Note: This guide assumes you’re using OpenSSH. For Windows users, use PuTTY or OpenSSH for Windows.
Top comments (0)