An SSH config file saves your server addresses, usernames, SSH ports, private keys and jump hosts, so you can connect with a short command like ssh production. OpenSSH reads this file on your local computer, not the server.
Use the examples below on Windows, macOS or Linux. Start with one Host block, inspect the effective settings with ssh -G, and then build up to multiple hosts, key selection, ProxyJump and shared defaults.
Add this to your client-side config file (replace the example-only address and account):
Host production
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519Verify it without making a connection, then use the alias:
ssh -G productionAfter confirming the settings and replacing the example values, connect with ssh production.
Note: 203.0.113.10 is a documentation address and cannot be used as your VPS. The IdentityFile must refer to a private key that exists on your machine.
What is an SSH config file?
ssh_config contains settings for the OpenSSH client used by ssh, scp and sftp. A client config is different from the server's sshd_config; editing it does not change which connections a server accepts.
Each Host block applies to a hostname, alias or pattern. HostName is the actual destination, User is the account on that host and Port is its SSH TCP port. New client commands read the file automatically — no SSH-server restart is necessary.
| File | Purpose |
|---|---|
~/.ssh/config | Your per-user OpenSSH client settings on macOS / Linux |
%USERPROFILE%\.ssh\config | Windows native OpenSSH client settings |
/etc/ssh/ssh_config | System-wide OpenSSH client defaults on Linux |
/etc/ssh/sshd_config | Server-side configuration; a different file with a different purpose |
Client command-line options take precedence over most config values. Within matching config blocks, the first value usually wins. IdentityFile is an important exception because multiple entries can accumulate.
Create or edit the SSH config file
Windows 10 / 11: PowerShell and Notepad
Native Windows OpenSSH normally reads C:\Users\YOUR_NAME\.ssh\config. Create the directory and the file only if absent, then edit it without overwriting existing hosts:
ssh -V
$sshDir = Join-Path $env:USERPROFILE '.ssh'
New-Item -ItemType Directory -Path $sshDir -Force | Out-Null
$config = Join-Path $sshDir 'config'
if (-not (Test-Path $config)) {
New-Item -ItemType File -Path $config | Out-Null
}
notepad $configSave as config without .txt. Windows OpenSSH and SSH inside WSL normally use different home directories and therefore different config files. If your alias works in one terminal but not the other, check which SSH executable is running.
macOS / Linux: Terminal
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config
nano ~/.ssh/configThe commands above preserve any existing contents. Save in Nano with Ctrl+O, Enter and Ctrl+X. On Linux/macOS the file must not be writable by other users; 600 is a safe default, not the only permitted mode.
Example 1: A basic SSH config with username, key and port
Suppose you currently enter the full command below every time:
ssh -i ~/.ssh/id_ed25519 -p 2222 [email protected]Save these options together under one name:
Host production
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519Now use ssh production. The config file does not create the private key or install its public half on the server; those are separate steps covered in generating an SSH key.
For short aliases only, see our dedicated SSH alias guide. This article continues with reusable client configuration beyond aliases.
Example 2: Verify the effective config with ssh -G
ssh -G expands the options that OpenSSH would use, then exits without contacting the server. It is the quickest way to verify a change, including placeholder hosts and jump-host rules.
ssh -G production | grep -E '^(hostname|user|port|identityfile|proxyjump) 'ssh -G production | Select-String -Pattern '^(hostname|user|port|identityfile|proxyjump) 'For the basic example above, the important output looks like this (the exact key path varies by OS):
hostname 203.0.113.10
user deploy
port 2222
identityfile ~/.ssh/id_ed25519You can also test another config file with ssh -F path/to/config -G production, useful when diagnosing conflicts. ssh -v production shows configuration loading and actual connection attempts, but unlike -G it makes a network connection.
ssh -G. This screenshot uses a separate demonstration config, including a jump host.Example 3: Configure multiple servers
Keep development, staging and production separate. Each Host starts a new matching block; a blank line is optional but improves readability:
Host dev
HostName dev.example.com
User devuser
Host staging
HostName staging.example.com
User deploy
Port 2202
Host production
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519_prodUse ssh dev, ssh staging or ssh production. The same definitions are available to native OpenSSH file transfer tools:
sftp production
scp ./report.txt production:/tmp/report.txtThe server still needs to be reachable, and your account needs access to the remote file path.
The editor screenshot below shows a separate demonstration setup using development, staging and production entries, plus shared Host * defaults.
Host * defaults.Example 4: Choose different SSH keys for each server
Use a dedicated private key for work, personal servers or Git services. Set IdentityFile to the private key path (without .pub).
Host production
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
IdentitiesOnly yes
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yesUse a Git remote like git@github-work:ORG/REPO.git to select the separate GitHub identity. The key must already be registered with the corresponding GitHub account.
Most ssh_config settings keep the first value they encounter, but multiple IdentityFile directives add keys to the identity list. IdentitiesOnly yes stops unrelated agent identities being offered; it does not magically reduce multiple explicitly configured identity files to one. Check ssh -G production when debugging key selection.
See SSH IdentityFile and Permission denied (publickey) for troubleshooting.
Example 5: A server on a custom SSH port
Save a non-standard port once instead of repeating -p in every connection:
Host vps
HostName 198.51.100.25
User ubuntu
Port 2202Then use ssh vps, sftp vps or scp file.txt vps:/tmp/. In an ordinary SSH command, the port flag is -p; scp uses -P. Using a Host definition avoids that flag difference.
Example 6: Host wildcards and configuration precedence
Host patterns such as dev-* or *.example.com share settings. A Host * block defines defaults for every destination. Put specific blocks first because OpenSSH normally uses the first value obtained for each parameter.
Host production
HostName 203.0.113.10
User deploy
ServerAliveInterval 15
Host dev-*
User developer
Host *
ServerAliveInterval 60
ServerAliveCountMax 3production retains its 15-second keepalive interval. Other hosts inherit 60 seconds. A wildcard matches the original name you type after ssh, unless more advanced hostname canonicalization applies.
For a precise readout use ssh -G production; do not assume that the last matching block overrides an earlier one.
Example 7: ProxyJump through a bastion host
If an internal server is reachable only through a bastion, define the two hosts separately. ProxyJump creates the intermediate SSH connection and then forwards traffic to the target:
Host bastion
HostName bastion.example.com
User admin
IdentityFile ~/.ssh/id_ed25519_bastion
Host internal-db
HostName 10.0.0.20
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519_internal
ProxyJump bastionConnect with ssh internal-db. The private address 10.0.0.20 is resolved/reached from the bastion network; it does not need to be reachable directly from your laptop.
Jump-host settings do not automatically inherit the destination's options. Configure Host bastion explicitly, and avoid adding ForwardAgent yes globally. Review SSH tunneling for forwarding use cases.
Example 8: Keep idle SSH sessions alive
Firewalls and NAT gateways can drop idle TCP sessions. Client-side SSH keepalive messages help detect lost connectivity and may keep idle paths active:
Host *
ServerAliveInterval 60
ServerAliveCountMax 3OpenSSH sends an encrypted keepalive probe after the configured interval of no received data and disconnects after the configured number of unanswered probes. Keepalives cannot repair an actually broken network or keep an app running after the SSH session ends. More in SSH keepalive.
Example 9: Split a large config with Include
When your config grows, keep separate files in ~/.ssh/config.d/. Start the main ~/.ssh/config with an Include line:
Include ~/.ssh/config.d/*
Host *
ServerAliveInterval 60Each file in config.d can contain its own Host blocks. Create the directory first (mkdir -p ~/.ssh/config.d on macOS/Linux, or create it in File Explorer on Windows). Include paths may use globs and are processed in lexical order.
Placement matters: an Include after Host production may be processed under that active host context instead of globally. For predictable shared configuration, put global Include directives before the host blocks. Test with ssh -G.
Example 10: A reusable local port-forwarding profile
A LocalForward directive can expose a remote-only service to your local computer over an SSH connection. For example, reach a PostgreSQL instance that listens only on loopback on the SSH server:
Host database-tunnel
HostName db-gateway.example.com
User deploy
LocalForward 127.0.0.1:15432 127.0.0.1:5432
ExitOnForwardFailure yesRun ssh -N database-tunnel and, in another terminal, connect your database tool to 127.0.0.1:15432. The destination host and SSH server must permit this forward. The second 127.0.0.1 is interpreted on the remote side. Keep the first bind address local to avoid exposing the port on other network interfaces.
Example 11: Safe StrictHostKeyChecking settings
StrictHostKeyChecking controls whether the SSH client trusts a server's host key. It is distinct from IdentityFile, which selects your authentication key.
| Value | Behavior | Typical use |
|---|---|---|
ask | Prompt for previously unknown keys; reject changed keys | Normal interactive use |
yes | Do not automatically trust unknown keys | Pre-provisioned, verified host keys |
accept-new | Trust new keys automatically, reject changed keys | Automation where trust-on-first-use is acceptable |
no | Permit changed keys subject to SSH restrictions | Avoid as a general workaround |
Host ephemeral-test
HostName 192.0.2.25
StrictHostKeyChecking accept-newFor high-assurance automation, verify and provision host fingerprints from a trusted source first, then use yes. accept-new protects against changes after first trust but cannot independently authenticate a brand-new host. Never set StrictHostKeyChecking no everywhere to suppress warnings.
Example 12: Fix bad owner or permissions on config
If SSH reports Bad owner or permissions on ~/.ssh/config, inspect file ownership and permissions before making changes:
ls -ld ~/.ssh ~/.ssh/config
chmod 700 ~/.ssh
chmod 600 ~/.ssh/configOn Unix-like systems the config must be owned appropriately and not be writable by group or others; 600 is the simplest safe mode, but 644 may also be accepted because it is not group- or other-writable. If the owner is wrong, investigate how the file was created before changing ownership.
Windows controls access through NTFS ACLs, not chmod. Inspect rather than blindly resetting permissions:
Get-Acl "$env:USERPROFILE\.ssh\config" | Format-List
icacls "$env:USERPROFILE\.ssh\config"Remove only confirmed excess write permissions and preserve your account's access, SYSTEM and appropriate administrative access.
Complete SSH config file example
Here is a realistic configuration for local development, staging and an internal production host behind a bastion. It combines several of the examples above. Substitute actual addresses and keys before connecting:
Host development
HostName dev.example.com
User developer
IdentityFile ~/.ssh/id_ed25519_dev
IdentitiesOnly yes
Host staging
HostName staging.example.com
User deploy
Port 2202
IdentityFile ~/.ssh/id_ed25519_staging
IdentitiesOnly yes
Host bastion
HostName bastion.example.com
User admin
IdentityFile ~/.ssh/id_ed25519_bastion
Host production
HostName 10.0.0.20
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
IdentitiesOnly yes
ProxyJump bastion
Host *
ServerAliveInterval 60
ServerAliveCountMax 3After saving, inspect each host with ssh -G development, ssh -G staging and ssh -G production. Your private key files must already exist and their public keys must be authorized by the corresponding servers.
Common SSH config options at a glance
| Directive | What it controls |
|---|---|
Host | Host alias or matching pattern |
HostName | Real server hostname/IP |
User | Remote account |
Port | Remote SSH TCP port |
IdentityFile | Local key selection; multiple values may accumulate |
IdentitiesOnly | Ignore unrelated agent-provided identities |
ProxyJump | Connect through bastion/jump hosts |
Include | Read additional config files |
Match | Conditional client configuration |
LocalForward | Local-to-remote TCP forwarding |
ServerAliveInterval | Keepalive interval in seconds |
ServerAliveCountMax | Unanswered keepalive count before disconnect |
StrictHostKeyChecking | Handling new/changed server host keys |
These options are described in the OpenSSH ssh_config(5) manual. Avoid copying advanced directives into Host * until you understand their effect on every destination.
Windows, macOS and WSL: common differences
The basic config syntax is shared by native Windows OpenSSH, macOS and Linux. File locations and key-file permissions differ:
| Platform | Typical per-user config | Editor |
|---|---|---|
| Windows PowerShell | C:\Users\NAME\.ssh\config | Notepad / VS Code |
| macOS / Linux | ~/.ssh/config | Nano / VS Code |
| WSL | Linux user's ~/.ssh/config within WSL | Nano / VS Code |
If you copy an example containing $env:USERPROFILE into Bash it will not work; that variable syntax is PowerShell-specific. OpenSSH's ~/.ssh/keyname syntax works inside IdentityFile in typical Windows and Unix OpenSSH builds.
Troubleshooting SSH config errors
| Symptom | First check |
|---|---|
hostname is still the alias | Correct file and exact Host spelling; check with ssh -G |
Wrong user or port | Earlier Host or wildcard entries; first-value precedence |
| Wrong identity / too many keys | All IdentityFile entries and IdentitiesOnly yes |
Windows config.txt | Save as config without an extension |
Bad configuration option | Typo or unsupported keyword; inspect reported file and line |
Bad owner or permissions | Unix ownership/mode or Windows file ACL |
Permission denied (publickey) | Authorized public key and selected remote account |
| Connection refused / timeout | Server port, firewall, hostname and SSH service |
ssh -G productionssh -v productionWhen ssh -G resolves the correct address and options but authentication fails, your config may be working; investigate server-side authorization instead of regenerating keys or disabling host-key verification.
Managing SSH workspaces after setup
OpenSSH config is excellent for storing host settings. After you connect, you may still need separate terminals, SFTP transfers, an editor and monitoring tools. ShadeTerm brings terminals, SFTP files, remote editing and monitoring together in a Windows desktop workspace.
ShadeTerm is a complementary graphical workflow, not a substitute for correct SSH authentication or server-side access controls. Explore the Windows app when you are ready to manage several servers.
SSH config FAQ
Where do I put the SSH config file?
In ~/.ssh/config on macOS/Linux, or %USERPROFILE%\.ssh\config with native Windows OpenSSH. It must be named exactly config.
Do I need to restart SSH after editing it?
No. The next OpenSSH client invocation rereads the client config. You do not need to restart sshd for changes on your own computer.
Can I use one SSH config for multiple hosts?
Yes. Define several Host blocks or use Include to split them into files. Verify each with ssh -G name.
Does IdentityFile point to a private or public key?
Normally the private key file without .pub. OpenSSH also has supported agent-based cases for public-key filenames; ordinary local SSH authentication should point to a private identity you control.
Will config aliases work with SCP and SFTP?
Yes for the OpenSSH scp and sftp commands: use a configured alias as the destination name.
What is the difference between ssh_config and sshd_config?
ssh_config configures the computer initiating a connection. sshd_config configures the OpenSSH server that accepts incoming connections.
Official references and deeper guides
These examples follow the OpenSSH client configuration manual. See also Linuxize's SSH config walkthrough and SSH.com's broader option reference.
For narrower problems, ShadeTerm has focused guides to SSH aliases, IdentityFile, keepalives, port forwarding and server-side sshd_config.
Conclusion: create, verify, then connect
Keep your local SSH config simple and readable: add individual hosts first, use ssh -G to inspect the options that apply, and add shared defaults or advanced features only when needed. The same config can then help with terminals, SCP and SFTP without repeating usernames, ports and key paths.