id rsa
id_rsa: The Complete Guide to SSH RSA Private Keys — Setup, Troubleshooting & Security Best Practices
Key Takeaways
- id_rsa is the default SSH private key generated by OpenSSH using the RSA algorithm. Its public counterpart is stored in
id_rsa.pub. - Common errors — "Permission denied (publickey)" and "No such file or directory" — are usually caused by incorrect file permissions, missing public key on the server, or wrong key path configuration.
- File permissions must be exact: private key at
600, directory at700. Anything looser will cause OpenSSH to refuse the key. - RSA is still widely supported but SHA-1 based; for new deployments consider
ed25519orrsa-sha2-256/512with 4096-bit keys for stronger security. - Never share your
id_rsaprivate key. Treat it like a password. Use a passphrase for extra protection and store backups in a secure location.
What Is id_rsa?
Defining the id_rsa File
The id_rsa file is the default SSH private key created by OpenSSH when you generate an RSA key pair. It lives in your home directory under ~/.ssh/ and is used to authenticate you to remote servers without a password.
Alongside it, OpenSSH creates id_rsa.pub — the public key that you copy to remote servers. The relationship is simple:
id_rsa(private): Stays on your machine. Never share it.id_rsa.pub(public): Goes into~/.ssh/authorized_keyson every server you want to access.
How RSA Key Authentication Works
When you run ssh user@server, the following happens behind the scenes:
- Your SSH client reads
id_rsafrom~/.ssh/. - The server checks whether the matching public key exists in your
authorized_keysfile. - A cryptographic challenge-response exchange verifies your identity without transmitting the private key.
- If the math checks out, you're logged in.
The private key never leaves your machine. This is what makes key-based authentication more secure than password login.
How to Generate an id_rsa Key Pair
Step-by-Step: Creating Your Key
Open a terminal and run the following command:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This command:
- -t rsa — Specifies the RSA algorithm.
- -b 4096 — Sets a 4096-bit key length (recommended over the older 2048-bit default).
- -C — Adds a comment (usually your email) to identify the key.
Interactive Prompts Explained
| Prompt | What to Enter | Why It Matters |
|---|---|---|
| Enter file in which to save the key | Press Enter for default (~/.ssh/id_rsa) |
Default path is recognized automatically by SSH. Custom paths require manual -i flag. |
| Type a strong passphrase (or press Enter for none) | A passphrase encrypts the private key at rest. Strongly recommended for production use. | |
| Confirm passphrase | Type it again | Prevents typos that would lock you out of your own key. |
Verifying Generation
After creation, confirm both files exist:
ls -la ~/.ssh/id_rsa*
You should see both id_rsa (private) and id_rsa.pub (public).
How to Add Your id_rsa.pub to a Remote Server
Using ssh-copy-id (Fastest Method)
ssh-copy-id user@server-ip
This appends your public key to the remote server's ~/.ssh/authorized_keys automatically.
Manual Method (When ssh-copy-id Isn't Available)
# On your local machine, print the public key:
cat ~/.ssh/id_rsa.pub
# Then on the remote server, append it:
echo "PASTE_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys
Checking the Result
cat ~/.ssh/authorized_keys
Confirm your public key appears on a single line in the file.
Troubleshooting Common id_rsa Errors
Error 1: "Permission denied (publickey)"
This is the most frequent issue. It means the server rejected your key. Follow this checklist:
Quick-Fix Checklist
- ✅ Check local file permissions:
chmod 700 ~/.ssh chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub - ✅ Verify the public key is on the server: Confirm
id_rsa.pubcontent exists in~/.ssh/authorized_keys. - ✅ Check server-side permissions:
chmod 700 ~/ chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys - ✅ Ensure SSH service allows pubkey auth: In
/etc/ssh/sshd_config, confirm these lines are present and uncommented:PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys - ✅ Restart the SSH daemon after config changes:
sudo systemctl restart sshd - ✅ Verify you're using the right key: If you have multiple keys, specify the correct one:
ssh -i ~/.ssh/id_rsa user@server
Error 2: "No such file or directory"
SSH can't find id_rsa in ~/.ssh/.
- Generate a new key:
ssh-keygen -t rsa -b 4096 - Or specify an existing key with
ssh -i /path/to/key user@server