Understanding SSH id_rsa Private Keys
Learn what ~/.ssh/id_rsa is, how SSH public-key authentication works, how to create and use keys, and how to protect, inspect, rotate, and revoke them securely.
SSH (Secure Shell) uses cryptographic keys to authenticate users to remote systems, transfer files, create tunnels, and support source-control or automation workflows. This lesson explains the conventional id_rsa private-key filename, how it relates to its public key, and how to manage it safely.
What id_rsa Means
id_rsa is the conventional filename for an RSA private key used by OpenSSH clients. It is not a special required filename. An RSA key can be stored under a descriptive name such as ~/.ssh/id_rsa_compat, and a key using another algorithm may use a different name, such as id_ed25519.
A private key is secret cryptographic material. During SSH authentication, it proves that you control a corresponding public key. The private key must remain on the client device and must not be sent to the server.
How SSH Public-Key Authentication Works
An SSH key pair contains two mathematically related values:
- Private key: the secret credential retained by the user, device, or automation identity.
- Public key: the non-secret counterpart installed on a server or registered with a service.
For a server login, the remote account lists permitted public keys in its ~/.ssh/authorized_keys file. The SSH client asks to authenticate with one of its identities. The server checks whether the matching public key is authorized and sends an authentication challenge. The client uses the private key to produce proof, usually a cryptographic signature. The server verifies that proof with the public key.
The private key is not transmitted during this exchange. Possession of the private key is demonstrated without revealing the key itself. Anyone who obtains a usable private key may be able to authenticate wherever its public key is still authorized.
Where SSH Keys and Configuration Files Live
The usual per-user SSH directory is ~/.ssh, where ~ means the current user's home directory. The exact home-directory path differs across operating systems and account environments, but the SSH directory convention is widely used.
| File or location | Typical side | Purpose | Sensitivity |
|---|---|---|---|
~/.ssh/id_rsa | Client | Conventional RSA private key | Secret; protect strongly |
~/.ssh/id_rsa.pub | Client | Public key corresponding to id_rsa | Shareable, although still useful to inventory |
~/.ssh/config | Client | Host-specific SSH client settings, including IdentityFile | Usually not secret, but may reveal host and account details |
~/.ssh/known_hosts | Client | Recorded server host keys used to detect unexpected server identity changes | Not a private credential; protect integrity |
~/.ssh/authorized_keys | Server | Public keys authorized for one server account | Not secret, but changes control account access |
An RSA setup may also include ~/.ssh/id_rsa-cert.pub. This is a public certificate associated with a key when an SSH certificate system is being used; it is not the private key itself.
For a comparison, id_ecdsa conventionally names an ECDSA private key, while id_dsa refers to the older DSA naming convention.
Protecting an id_rsa Private Key
Treat id_rsa like a password or other high-value credential. Never post it, commit it to version control, email it, paste it into a ticket, or include it in a support request. Do not display its contents in a shared terminal, screen recording, log, or chat.
Passphrases
A passphrase encrypts the private-key file at rest. If someone copies the file, the passphrase makes immediate use more difficult and may prevent authentication altogether if the passphrase is strong and unknown to the attacker. A passphrase does not help if it is written beside the key, reused from a compromised password, or entered into an untrusted program.
Permissions
Restrict access to the SSH directory and private key. A common Unix-like configuration is:
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_rsa && chmod 644 ~/.ssh/id_rsa.pub
The directory and private key should be owned by the intended local account. Exact permission enforcement varies by platform and SSH implementation. The public key can normally be readable, but the private key should not be readable by other local users.
| Path | Typical permission mode | Reason |
|---|---|---|
~/.ssh | 700 | Only the account can list or access the directory |
| Private key file | 600 | Only the owner can read and write secret key material |
| Public key file | 644 | Public data may be readable while remaining owner-managed |
authorized_keys | Often 600 | Prevents unintended local modification or access; server policy may vary |
Backup and recovery
Back up a private key only when there is a clear recovery need. Store the backup in encrypted storage with strict access control, and document its owner and purpose. Do not place an unencrypted private key in a shared drive or general-purpose backup visible to many people. Keep an inventory of the public-key fingerprint, owner, device, and systems where the key is authorized.
Creating SSH Keys
Preferred choice for new keys: Ed25519
Ed25519 is commonly preferred for new general-purpose SSH user keys because it is modern, compact, and broadly supported by current SSH implementations.
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519 -C "user@device"
When prompted, choose a strong passphrase and enter it again to confirm. The comment helps identify the key; it is a label, not a security control. The command creates a private key and a public key, normally ~/.ssh/id_ed25519 and ~/.ssh/id_ed25519.pub.
RSA for compatibility
RSA remains useful when an older server, service, or organizational policy requires it. Use a descriptive filename so it is clear why the key exists:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_compat -C "user@device-compat"
For new RSA keys, use a modulus size accepted by the systems and policy involved; 4096 bits is a common compatibility-oriented choice. Do not create a new RSA key merely because the filename id_rsa is familiar.
| Algorithm | Recommended use | Compatibility considerations | Notes |
|---|---|---|---|
| Ed25519 | Default choice for new user-authentication keys | Requires reasonably modern SSH support | Compact and modern |
| RSA | Older systems or explicit policy requirements | Usually widely supported, but signature policies may differ | Use an appropriate modulus size and current signature support |
| ECDSA | Specific compatibility or policy needs | Support is common, but organizational preferences vary | Do not confuse with host-key configuration |
| DSA | Generally no new use | Disabled by many modern implementations | Deprecated; avoid where possible |
These are SSH user-authentication key types. SSH servers also have host keys, which identify the server to clients. A user's id_rsa is not a host key.
Installing a Public Key
Copy only the contents of the .pub file to the remote account's authorized_keys file. Never copy the private key to the server as an installation method.
Where available, ssh-copy-id performs the common installation workflow:
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@example.com
This transfers the public key, not the private key. It normally uses an existing password or another permitted login method to append the key for the selected remote account.
For manual installation, an administrator or existing access path must append one complete public-key line to the remote user's ~/.ssh/authorized_keys. The remote account must own its home directory, SSH directory, and authorization file, and server policy must allow public-key authentication. Common directory and file restrictions are similar to:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Do not overwrite an existing authorized_keys file accidentally. Review entries before removing or replacing them, especially when they are the only way to access an account.
Using a Named Private Key
Default discovery and one-time selection
SSH clients may automatically look for conventional identities in ~/.ssh. This implicit discovery is convenient, but it can become confusing when several keys exist. Select a key for one connection with -i:
ssh -i ~/.ssh/id_rsa_compat user@example.com
The selected path identifies the private key. SSH reads the corresponding public key when needed; the public key still must be authorized for the remote account.
Persistent host-specific configuration
For repeated connections, place host-specific settings in ~/.ssh/config:
Host example-server
HostName example.com
User user
IdentityFile ~/.ssh/id_rsa_compat
IdentitiesOnly yes
Then connect using the alias:
ssh example-server
IdentityFile specifies the private key. IdentitiesOnly yes limits the client to configured identities instead of offering unrelated keys from an agent or default locations. This is particularly useful when work and personal accounts use different keys.
Using ssh-agent
ssh-agent is a process that temporarily holds unlocked private keys and performs authentication operations on their behalf. Add a passphrase-protected key to an active agent:
ssh-add ~/.ssh/id_rsa_compat
Enter the passphrase locally when prompted. The key can then be used during the agent's session without repeatedly typing the passphrase. Load only keys needed for the session, and understand that any process able to use the agent may potentially authenticate as the identities it holds. Avoid indiscriminate agent forwarding to untrusted servers.
Inspecting Keys Without Exposing Secrets
Fingerprints are short, hash-based identifiers used to compare and inventory keys. They are not replacements for the private key and are generally safe to share when needed for identification, subject to organizational policy.
ssh-keygen -lf ~/.ssh/id_rsa.pub
This displays the public key's bit length, fingerprint, and key type. Compare it with the fingerprint recorded by a server administrator or service interface.
If the public-key file is missing, derive it locally from the private key:
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
Run this only on a trusted local machine. The command reads the private key but writes only the derived public key. Do not substitute a private-key path into a command intended to print or share public data.
Verbose SSH diagnostics can show which identities are offered:
ssh -vvv -i ~/.ssh/id_rsa_compat user@example.com
Review output for offered identities, accepted keys, and refusal messages. Check verbose logs before sharing them because they may reveal usernames, hostnames, file paths, or other environment details.
Operational Hygiene and Key Rotation
- Use separate keys for distinct devices, users, environments, or automation identities when practical.
- Do not share one private key among multiple people. Individual keys make ownership, removal, and auditing possible.
- Use meaningful comments and maintain an inventory of fingerprints, owners, creation dates, authorized systems, and intended purpose.
- Use dedicated restricted keys or managed credentials for automation. Limit their accounts and permissions instead of reusing a personal key.
- Remove unused public-key entries from server accounts and services.
- Rotate keys by generating a replacement, installing its public key, testing it, and then removing the old authorization.
Key rotation means replacing a credential and updating every system that authorizes it. Keep the old key only for the minimum overlap needed to avoid losing access, and remove it once the replacement is confirmed.
What to Do After Private-Key Exposure
Assume an exposed private key can be used by an unauthorized party, even if you do not know whether it was copied. A passphrase reduces risk but does not eliminate the need to respond.
| Step | Action | Expected result |
|---|---|---|
| Identify affected key | Match the key to its public-key fingerprint and inventory | You know which accounts and services may be affected |
| Remove public-key authorization | Delete the matching public-key entries from authorized_keys and service settings | The exposed key should no longer authenticate |
| Create replacement | Generate a new key pair with a new passphrase and purpose-specific name | A fresh credential is available |
| Update services and automation | Install the new public key and update approved clients, jobs, and secret stores | Legitimate access uses the replacement |
| Confirm revocation | Test the replacement and verify the old key is rejected | Access works as intended and the old credential is disabled |
| Investigate possible use | Review authentication logs and follow incident procedures | Suspicious activity can be identified and contained |
Troubleshooting Common Problems
Permission denied (publickey)
- Verify that the matching public key is in the correct remote account's
authorized_keys. - Check the username, hostname, and selected private-key path.
- Confirm remote ownership and permissions allow the SSH server to read the authorization file.
- Check whether the server permits public-key authentication and accepts the key algorithm.
- Use
ssh -vvvto identify which identities were offered and why authentication was refused.
WARNING: UNPROTECTED PRIVATE KEY FILE
The private key is readable by other local users or has unsuitable ownership. Restrict the SSH directory and key file, then verify ownership. A typical starting point is chmod 700 ~/.ssh and chmod 600 ~/.ssh/id_rsa.
The client offers too many keys
Many identities may be loaded in ssh-agent, and a server may reject authentication after a limited number of attempts. Select the intended key with -i, use IdentitiesOnly yes with a host-specific IdentityFile, and review which keys are loaded in the agent.
The passphrase is requested repeatedly
The key may not be loaded in a usable agent, or desktop credential integration may be unavailable. Start or verify an agent, add the intended key with ssh-add, and confirm that the client is using the same key.
An older RSA key is rejected
Current client or server policy may no longer accept the older RSA signature method, or the key may have been rotated or removed. Review verbose output and server policy with an administrator. Use a supported modern key where permitted; do not weaken cryptographic policy just to preserve an obsolete key.
A host identity warning appears
This concerns the server's host key and known_hosts, not your id_rsa user key. The host may have been replaced or reconfigured, or the connection may be reaching an unexpected system. Verify the host-key fingerprint through a trusted administrative channel before changing known_hosts.
Exam-Relevant Notes
id_rsais conventionally an RSA private key;id_rsa.pubis its public counterpart.- The private key stays with the client. The public key is installed on the server or service.
authorized_keysauthorizes public keys for a particular server account.- A passphrase protects a private key file at rest; it does not make a leaked key safe to leave authorized.
known_hostsstores client-side server host-key records and is separate from user-authentication keys.- Ed25519 is commonly preferred for new keys; RSA remains useful for compatibility; DSA should not be newly created.
- After exposure, revoke the old public key, issue a replacement, update services, and investigate possible use.