- Регистрация
- 9 Май 2015
- Сообщения
- 1,549
- Баллы
- 155
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.
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).
Use the ssh-copy-id command to install your public key on the server:
ssh-copy-id user@server_ip
- 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
- If successful, you’ll be connected to the server without a password prompt!
If you still need a password, check these common issues:
- Permissions: Ensure your client’s ~/.ssh folder is 700 and the private key (id_rsa) is 600.
- Server-side config: Verify PubkeyAuthentication yes is enabled in ~/.ssh/authorized_keys on the server.
- Firewall: Ensure port 22 (default SSH port) is open on the server.
- 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.
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.
Источник: