TL;DR
Apps shouldn’t be able to read your private SSH keys. This guide shows how to make sure they can’t, using file permissions and key agent forwarding.
How Apps Can Access Your Keys (and Why It’s Bad)
If an app has access to the ~/.ssh directory or its files, it could steal your SSH keys. This lets attackers log in to servers as you without needing your password.
Steps to Protect Your SSH Keys
- Check File Permissions on ~/.ssh
- The
~/.sshdirectory should only be readable, writable and executable by *you*. - Use the following command to check:
ls -ld ~/.ssh - The
- You should see something like this (the username will be different):
- If the permissions are too open, fix them with:
- Check File Permissions on Private Keys
- Your private key files (usually named
id_rsaor similar) should *only* be readable by you. - Use this command to check:
ls -l ~/.ssh/id_rsa - Your private key files (usually named
- You should see something like this:
- If the permissions are too open, fix them with:
- Use an SSH Agent
- An SSH agent stores your decrypted private key in memory. Apps can then use the agent to authenticate without directly accessing the key file. This is much safer.
- Start the agent (usually happens automatically when you log in). If not, try:
eval "$(ssh-agent -s)" - Add your private key to the agent:
- Avoid Key Agent Forwarding When Unnecessary
- Key agent forwarding lets a remote server access your local SSH agent. This is convenient, but risky if the server is compromised.
- Only use it when you absolutely need to (e.g., for Git operations over an untrusted network).
- To disable forwarding in your
~/.ssh/configfile, add:
Host * ForwardAgent no - Be Careful with Apps Requesting Key Access
- Think carefully before granting any app access to your
~/.sshdirectory or files. - If an app asks for key access, research it thoroughly first.
- Think carefully before granting any app access to your
drwx------ 3 yourusername yourgroup 4096 Oct 26 10:00 .ssh
chmod 700 ~/.ssh
-rw------- 1 yourusername yourgroup 2405 Oct 26 10:00 id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa
Checking Your Setup
After following these steps, double-check the file permissions and make sure you’re using an SSH agent correctly.

