How do I create a reusable SSH alias on Windows?
A Host entry in your local SSH configuration gives a server a memorable connection name. It can hold the hostname, username, port and identity path, while the private key remains in its own protected file.
Instructions
1. Locate the user configuration
The usual file is .ssh/config within your Windows profile, with no .txt extension. Inspect any existing file before changing it so other aliases are preserved.
Get-Content -LiteralPath "$env:USERPROFILE\.ssh\config" -ErrorAction SilentlyContinueThis reads local client settings. Review the relevant entry privately because configuration may contain internal hostnames.
2. Add one clearly scoped Host entry
Use an editor to add a block named example-server. Set HostName to 203.0.113.10, User to adminuser, Port to the actual port, IdentityFile to the correct key path, and IdentitiesOnly to yes. Keep specific Host blocks before broad wildcard defaults. Do not overwrite the complete configuration just to add one server.
3. Inspect the alias before use
Check the final values and then connect using the alias.
ssh -G example-server | Select-String -Pattern "^hostname |^user |^port |^identityfile "
ssh example-server-G resolves configuration without connecting. The following command uses the saved alias.
Check the result
- The resolved hostname, user, port and identity file are correct.
- ssh example-server reaches the expected verified server.
Troubleshooting
- The alias is treated as a DNS hostname
- Check that the file is named config, not config.txt, in the current user’s .ssh directory.
- A value is unexpectedly overridden
- SSH generally uses the first applicable value; review wildcard entries and ordering.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
