Where are SSH keys stored? Linux, macOS and Windows

Find your SSH key files on Linux, macOS and Windows, plus where a server keeps authorized_keys and its own host keys, and how to list them.

5–8 minutes
Laptop on a desk seen from above

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:

FileWhat it isShare it?
id_ed25519Your private key (Ed25519 type)Never
id_ed25519.pubThe matching public keyYes, this is what you give servers
id_rsa and id_rsa.pubAn older RSA key pairPrivate: never. Public: yes
known_hostsFingerprints of servers you have connected to beforeNot needed
authorized_keysPublic keys allowed to log in to this machineNot needed
configYour shortcuts and per-server settingsNot 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 at C:\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 .ssh folder, and the reverse is also true.
  • PuTTY uses its own .ppk key 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, under HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys, not in a known_hosts file.

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.

  1. List the key files SSH looks for by default when connecting to a host:
ssh -G example.com | grep -i identityfile
  1. List the keys currently loaded into ssh-agent, the background program that holds unlocked keys in memory:
ssh-add -l
  1. Watch a real connection attempt. Lines containing Offering public key show each key being tried, and Server accepts key shows 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

SymptomCauseFix
ls: cannot access '~/.ssh'You have never made or used a key on this accountCreate one with ssh-keygen -t ed25519
UNPROTECTED PRIVATE KEY FILE!The private key can be read by other userschmod 600 on the key, chmod 700 on ~/.ssh
Key exists but server asks for a passwordKey has a custom name, or you used sudoUse ssh -i or an IdentityFile line, and drop sudo
Key works in Git Bash but not WSLWSL has a separate home folderCopy the key into WSL’s ~/.ssh and fix permissions
Server still rejects your keyPublic key is in the wrong account’s authorized_keysAdd it to the home folder of the user you log in as

Official documentation

Get the next guide

One email when there is something worth reading: new guides, errors going around, and hosting changes that affect your site.

No tracking pixels, and one click to leave.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.