Set up ssh host aliases in ~/.ssh/config

Turn ssh deploy@203.0.113.10 -p 2222 into just ssh web.

LinuxsshconfigLow risk
Add a Host block to ~/.ssh/config (Host web / HostName … / User … / Port …), then connect with ssh web.

01Command

Command
$ nano ~/.ssh/config && ssh web  # after adding: Host web / HostName 203.0.113.10 / User deploy / Port 2222

02What it does

~/.ssh/config is read by the ssh client on every connection. Each block starts with Host nickname and sets HostName, User, Port, IdentityFile, and more; options also apply to scp, rsync, and git (git@web:repo). Wildcards like Host * set defaults for everything. chmod 600 ~/.ssh/config keeps ssh from complaining about permissions.

03Risk

RiskLow risk
!Warning: A mistake in this file can lock you out of servers: options match the FIRST matching Host block, so put specific hosts above wildcard blocks. Keep a copy of the file before rewriting it, and test with ssh -G web to see the resolved settings.

04Undo

Undo
$ Remove the Host block from ~/.ssh/config to delete the alias

05Sources

  • ssh_config(5) — OpenSSH client configuration file
    man7.org · community · 2026-09-17
    Evidence: The per-user ~/.ssh/config file defines Host entries whose options (HostName, User, Port, IdentityFile) apply when the host alias is used on the ssh command line.

Last verified: 2026-09-18 · Category: Developer

06Related solutions