SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH → keys are stored in a hidden folder called .ssh inside your home folder, on Linux, macOS and Windows alike. This guide shows the exact path on each system, where a server keeps the keys it trusts, and how to find a key when it is not where you expected.
On your own computer, SSH keys live in **~/.ssh/**: /home/yourname/.ssh/ on Linux, /Users/yourname/.ssh/ on macOS and **C:\Users\yourname\.ssh\** on Windows. The private key is usually id_ed25519 (or id_rsa) and the public key is the same name ending in .pub. On a server, the public keys allowed to log in are listed in **~/.ssh/authorized_keys of the account you log in as, and the server’s own host keys are in /etc/ssh/**.
The files you will find in ~/.ssh
The ~ symbol is shorthand for your home folder. The dot at the start of .ssh makes it a hidden folder, which is why you do not see it in a normal file browser. Inside it you will usually find some of these files:
| File | What it is | Share it? |
|---|---|---|
id_ed25519 | Your private key (Ed25519 type) | Never |
id_ed25519.pub | The matching public key | Yes, this is what you give servers |
id_rsa and id_rsa.pub | An older RSA key pair | Private: never. Public: yes |
known_hosts | Fingerprints of servers you have connected to before | Not needed |
authorized_keys | Public keys allowed to log in to this machine | Not needed |
config | Your shortcuts and per-server settings | Not needed |
If you named a key yourself when you ran ssh-keygen, for example work_key, it will be in the same folder under that name, with work_key.pub beside it. If you are not sure how the private and public halves fit together, read what SSH keys are first.
Where SSH keys are stored on Linux
On Linux the folder is /home/yourname/.ssh/. For the root user it is /root/.ssh/, because root has its own home folder. To list what is there, open a terminal and run:
ls -la ~/.ssh
A typical result looks like this:
drwx------ 2 exampleco exampleco 4096 Oct 20 09:12 .
-rw------- 1 exampleco exampleco 411 Oct 20 09:12 id_ed25519
-rw-r--r-- 1 exampleco exampleco 99 Oct 20 09:12 id_ed25519.pub
-rw-r--r-- 1 exampleco exampleco 978 Oct 20 09:15 known_hosts
The letters on the left are permissions. The folder should be readable only by you (drwx------) and so should the private key (-rw-------). If they are wider than that, SSH refuses to use the key. Fix them with:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
If you run sudo ssh ..., SSH runs as root and looks in /root/.ssh/, not in your own folder. That is a common reason a key that “definitely exists” is ignored. Run ssh without sudo.
Where SSH keys are stored on macOS
macOS uses the same layout as Linux, with home folders under /Users/. Your keys are in /Users/yourname/.ssh/. In Terminal, the same command works:
ls -la ~/.ssh
To see the folder in Finder, press Cmd + Shift + G, type ~/.ssh and press Return. You can also show hidden files in any Finder window with Cmd + Shift + . (full stop).
If you use a passphrase, macOS can remember it in your Keychain so you are not asked every time:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Only the passphrase goes into Keychain. The key file itself stays in ~/.ssh/.
Where SSH keys are stored on Windows
Windows 10 and 11 include the OpenSSH client, and it keeps keys in your user profile at C:\Users\yourname\.ssh\. In PowerShell, list them with:
dir $env:USERPROFILE\.ssh
In File Explorer, paste %USERPROFILE%\.ssh into the address bar and press Enter.
A few Windows tools keep keys somewhere else, which explains most “missing key” puzzles:
- Git Bash uses the same folder, because its
~points atC:\Users\yourname. See the guide to Git Bash for Windows for how its paths map to Windows paths. - WSL (the Windows Subsystem for Linux) has its own separate Linux home folder,
/home/yourname/.ssh/. A key made inside WSL is not in your Windows.sshfolder, and the reverse is also true. - PuTTY uses its own
.ppkkey format and saves the file wherever you chose when you created it. PuTTY stores the host keys of servers you have trusted in the Windows registry, underHKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys, not in aknown_hostsfile.
On Windows the private key must be readable only by your account. If OpenSSH complains about permissions, check who has access with:
icacls $env:USERPROFILE\.ssh\id_ed25519
Only your user, SYSTEM and Administrators should be listed.
Where a server keeps SSH keys
When you log in to a server, two different sets of keys are involved, and they live in different places.
Keys allowed to log in: authorized_keys
Your public key goes into ~/.ssh/authorized_keys in the home folder of the account you log in as. If you connect as exampleco@203.0.113.10, that is /home/exampleco/.ssh/authorized_keys. Each line in the file is one public key. To check which file the SSH server reads, run this on the server:
sudo sshd -T | grep -i authorizedkeysfile
The default answer is .ssh/authorized_keys .ssh/authorized_keys2, meaning both files in the user’s home folder are checked. The guide on how to set up SSH keys shows how to add your key to this file safely.
On a Windows server running OpenSSH Server, ordinary users follow the same pattern in C:\Users\username\.ssh\authorized_keys. Accounts in the Administrators group are different: their keys go in C:\ProgramData\ssh\administrators_authorized_keys.
The server’s own identity: host keys
The server also has key pairs of its own, called host keys. They prove to your computer that it is talking to the real server and not an impostor. On Linux they are in /etc/ssh/:
ls /etc/ssh/ssh_host_*
You will see files such as ssh_host_ed25519_key and ssh_host_ed25519_key.pub. To print the fingerprint that your computer shows the first time you connect, run:
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
Your computer remembers that fingerprint in its own ~/.ssh/known_hosts file. On Windows servers, host keys live in C:\ProgramData\ssh\. The host key prompt itself is explained in how to connect to a server with SSH.
How to find which key SSH is actually using
If you have several keys, or a key in an unusual place, these commands show what SSH will try.
- List the key files SSH looks for by default when connecting to a host:
ssh -G example.com | grep -i identityfile
- List the keys currently loaded into ssh-agent, the background program that holds unlocked keys in memory:
ssh-add -l
- Watch a real connection attempt. Lines containing
Offering public keyshow each key being tried, andServer accepts keyshows the one that worked:
ssh -v exampleco@203.0.113.10
If your key has a non-default name, SSH will not try it unless you tell it to, either with ssh -i ~/.ssh/work_key exampleco@203.0.113.10 or with an IdentityFile line in ~/.ssh/config.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
ls: cannot access '~/.ssh' | You have never made or used a key on this account | Create one with ssh-keygen -t ed25519 |
UNPROTECTED PRIVATE KEY FILE! | The private key can be read by other users | chmod 600 on the key, chmod 700 on ~/.ssh |
| Key exists but server asks for a password | Key has a custom name, or you used sudo | Use ssh -i or an IdentityFile line, and drop sudo |
| Key works in Git Bash but not WSL | WSL has a separate home folder | Copy the key into WSL’s ~/.ssh and fix permissions |
| Server still rejects your key | Public key is in the wrong account’s authorized_keys | Add it to the home folder of the user you log in as |
Official documentation
- OpenSSH key management on Windows (Microsoft Learn)
- ssh_config manual page (OpenSSH)
Related
- What are SSH keys? explains how the private and public halves work together.
- How to set up SSH keys walks through creating a key and copying it to a server.
- How to connect to a server with SSH covers your first login and the host key prompt.
- SSH gives a one-line definition you can share.
Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.



