ssh web lands on the right machine
ssh web lands on the machine named by HostName.
Type ssh web and you land on that machine without retyping the user, address, and port. To put the alias and the machine on one page, open sitdraw.
What you stop retyping is user@host -p. What changes the result is one Host alias at the top of the file.
The first value stays
Alias block first
Put Host web at the top. HostName is the host you actually log into. 192.0.2.10 is a documentation address, not your server.
Wildcard last
Host * fills only directives that are not set yet. If it sets HostName earlier, the alias cannot replace that value.
Four lines decide where ssh web goes
| Directive | What this alias sets | Manual default |
|---|---|---|
| Host web | Applies only when you type web | * covers every host |
| HostName | Example address 192.0.2.10 | The name on the command line |
| User | Example user deploy | Otherwise you pass the user on the command line |
| IdentitiesOnly | yes, only keys from the config | no |
One alias that actually lands
- 01Lock down ~/.ssh/config
Create ~/.ssh if it is missing. The manual path is ~/.ssh/config. chmod 600: read/write for you, not writable by others.
- 02Put Host web above Host *
HostName is the real host. User is the login. Add Port only when it is not 22. For one key, add IdentityFile and set IdentitiesOnly yes.
- 03Run ssh -G web first
It prints the configuration after Host and Match, then exits. No shell. hostname should be 192.0.2.10 and user should be deploy. Any other value means an earlier setting already won.
- 04Then ssh web
This is the login. ssh -p 2222 web uses port 2222, because the command line is read before the file.
Host web
HostName 192.0.2.10
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host *
# later defaults only
ssh -G web
ssh webThe alias matches the web you type. HostName is the machine you log into.
To keep that map on one page, read the guide, then open a space from the start of the page.
Why does ssh web still use the name I typed?
HostName was already set by an earlier source. The command line wins. A Host * block higher in the file wins too. The first value stays. A later Host web cannot replace it.
Why does IdentityFile still try other keys?
IdentityFile adds to the list. It does not clear it. Agent identities are tried unless IdentitiesOnly is yes. The default is no.
Does Host web match the real hostname?
No. Host usually matches the command-line argument. HostName is the host you log into. CanonicalizeHostname defaults to no. Set to yes, the file is parsed again with the new name.
Read hostname before a shell
If hostname in ssh -G web is still wrong, the key is not the first thing to blame. Host * is probably above the alias.