SSH Private Key
An SSH private key is the secret half of an SSH key pair, kept on your own machine, usually at ~/.ssh/id_ed25519. It proves your identity by signing a challenge from the server and must never be shared.
Understanding SSH Private Keys
What Is an SSH Private Key?
The private key is the master key to every server holding your matching public key. Anyone who obtains it can log in as you, with no alert. The rule is absolute: never email it, paste it in chat, or commit it to Git.
How a Private Key Proves Your Identity
During login the server sends a challenge. Your client signs it locally with the private key and returns the signature. The server verifies it with the public key stored in authorized_keys. The private key itself never crosses the network.
How to Create and Protect a Private Key
ssh-keygen -t ed25519 -C "rahul@devops.in" # choose a strong passphrase chmod 700 ~/.sshchmod 600 ~/.ssh/id_ed25519 # SSH rejects keys that are too open eval "$(ssh-agent -s)"ssh-add ~/.ssh/id_ed25519 # enter passphrase oncessh-add -l # list loaded keys ssh-keygen -y -f ~/.ssh/id_ed25519 # validate key, print public partPer-host key selection in ~/.ssh/config:
Host mumbai-prod HostName 10.0.1.50 User rahul IdentityFile ~/.ssh/id_ed25519_prodWhat to Do If a Private Key Is Compromised
Treat it as compromised and rotate it immediately.
# 1. Generate a new pairssh-keygen -t ed25519 -C "rahul@devops.in"# 2. Deploy the new public key to every server# 3. Remove the old public key from every authorized_keys file# 4. Confirm the old key can no longer log inTroubleshooting Private Keys
| Symptom | Command | What to Look For |
|---|---|---|
| Permissions too open | chmod 600 key |
Key file mode |
| Wrong key used | ssh-add -l or ssh -v |
Which keys are offered |
| Agent not running | eval "$(ssh-agent -s)" |
Start the agent |
| Key format error | ssh-keygen -y -f key |
File integrity |
SecurityIf a private key is ever committed to Git, treat it as compromised even after deleting it, since clones and history may keep it. Rotate it and remove the old public key everywhere.
RememberAlways protect keys with a passphrase. An unprotected key on a stolen laptop is a ready-made credential for every server it unlocks.
Frequently Asked Questions
Does the private key ever leave my machine during SSH login?
No. Your client signs a server challenge locally and sends only the signature. Even a fully captured handshake does not reveal the private key.
How do I protect a private key if my laptop is stolen?
Use a passphrase when generating it, keep full-disk encryption on, and rotate the key if you suspect exposure. Without a passphrase, anyone with the file can use it.
Why does SSH say my private key permissions are too open?
SSH refuses keys readable by other users as a safety check. Set the file to mode 600 and the `~/.ssh` directory to 700.