DEV Community

kingyou
kingyou

Posted on

Passwordless SSH Setup in 5 Minutes

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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode
  • Replace user with your server username (e.g., ubuntu, root).
  • Replace server_ip with 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
Enter fullscreen mode Exit fullscreen mode
  • If successful, you’ll be connected to the server without a password prompt!

Troubleshooting

If you still need a password, check these common issues:

  1. Permissions: Ensure your client’s ~/.ssh folder is 700 and the private key (id_rsa) is 600.
  2. Server-side config: Verify PubkeyAuthentication yes is enabled in ~/.ssh/authorized_keys on the server.
  3. 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)