SSH config file: example for servers and GitHub
Give servers short names and choose the right key for each.
The SSH config file lets you type ssh myserver instead of a long command, and tells SSH which key to use for each server. Enter your details below and save the result as ~/.ssh/config.
Create your config file
Type your own values. The file below updates as you type, and nothing you type leaves your browser.
Host github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host myserver
HostName 203.0.113.10
User ubuntu
Port 22
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
ServerAliveInterval 60How this setup works
Step-by-step setup
- Make a key: ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519.
- Add the public key (~/.ssh/id_ed25519.pub) to GitHub or the server.
- Create ~/.ssh/config and paste the config above.
- Lock it down: chmod 600 ~/.ssh/config.
- Test: ssh myserver (or ssh -T git@github.com for GitHub).
What the important lines mean
- IdentitiesOnly yes uses only the key you named, which avoids “too many authentication failures”.
- ServerAliveInterval 60 stops idle connections from dropping.
Common errors and how to fix them
- Permission denied (publickey)
- The server does not have your public key, or the wrong key is used. Run ssh -v myserver to see which key is tried.
- Bad owner or permissions on config
- Run chmod 600 ~/.ssh/config.
- Wrong key is tried first, or too many authentication failures
- IdentityFile lines add up and all are tried in order, and ssh-agent may offer more keys. Add IdentitiesOnly yes so only the listed key is used.
- My Host * settings are ignored for one server
- The first value obtained for each setting wins, so put specific Host blocks at the top and Host * at the end.
Frequently asked questions
- Where is the SSH config file?
- On Linux and macOS it is ~/.ssh/config. On Windows it is C:\Users\YourName\.ssh\config. If it does not exist, create it.
- How do I use different keys for different servers?
- Add one Host block per server and set IdentityFile to the key for that server. Keep IdentitiesOnly yes so SSH tries only that key.
- Why do I get Permission denied (publickey)?
- The server does not have your public key, or SSH is offering a different key. Run ssh -v with your host name to see which key is tried, and add the matching .pub file to the server.
- How do I stop SSH sessions from dropping when idle?
- Set ServerAliveInterval (seconds between checks, default 0 which is off). With ServerAliveCountMax at its default of 3, an interval of 15 disconnects after about 45 seconds of no reply.
- How do I connect through a jump host?
- Use ProxyJump user@jumphost, with several hops separated by commas. Settings for the final host do not apply to the jump host, so give it its own Host block.
- What does AddKeysToAgent do?
- Values are no (default), yes, confirm, ask or a time. yes adds the key to ssh-agent the first time you use it.
- Can I split the config into several files?
- Yes. Include accepts paths with wildcards; matches are read in lexical order and relative paths resolve to ~/.ssh.
Free tools that help
Fix a problem with this setup
- Generate SSH key for GitHubCreate an SSH key with ssh-keygen, load it into ssh-agent, copy the public key and add it to GitHub, with the Windows and macOS differences.
- Git push rejectedFix "! [rejected] main -> main (fetch first)" and "failed to push some refs": pull the remote changes, handle protected branches and big files.
More developer configs
- .gitconfig setupSet your name, email, default branch and shortcuts once.
- .env file exampleCreate a .env file for your app: port, database address and a secret key.
- VS Code settings.jsonSet font, tab size, format on save and theme in your VS Code settings.
- .bashrc and .zshrc aliasesAdd handy shortcuts and settings to your terminal.
- .gitignore fileTick your languages and tools to get a .gitignore that keeps build files and secrets out of Git.
- .editorconfig fileMake every editor on your team use the same indent, line endings and encoding.