You’ve got two easy ways to do this, pick whichever feels cleaner to you:
────────────────────────────────────────────────
- Classic shell alias (quick-n-dirty, works only in your shell)
────────────────────────────────────────────────
- Open your shell’s RC file (e.g.
~/.bashrc, ~/.zshrc, ~/.config/fish/config.fish, etc.)
- Add an alias line:
# ~/.bashrc
alias ssh-name="ssh user@domain"
- Reload the file (or open a new terminal):
source ~/.bashrc # or zsh: source ~/.zshrc
- Now you just run:
ssh-name # notice the dash because alias names can’t contain spaces
PROS
• Fast and easy
• Works for any command, not just ssh
CONS
• Alias must be unique in your shell, so ssh-name (with a hyphen or other separator) is typical, not just ssh name with a space.
• Won’t automatically apply to scp, rsync, git, etc. (they all invoke ssh internally but bypass the alias).
────────────────────────────────────────────────
2) The “right” way: ~/.ssh/config (portable, scp-/rsync-friendly)
────────────────────────────────────────────────
- If it doesn’t exist, create
~/.ssh/config and lock permissions:
touch ~/.ssh/config
chmod 600 ~/.ssh/config
- Add a host block:
Host name # whatever nickname you want — no spaces
HostName domain
User user
Port 22 # optional if not standard
IdentityFile ~/.ssh/id_ed25519 # optional key
- Save, and now you can simply type:
ssh name
scp file.txt name:/var/www/
git clone name:/repo.git # works in git too
PROS
• Works with ssh, scp, sftp, rsync, git, etc.
• Lets you specify keys, ports, ProxyJump, etc. per host.
• No worry about shell-alias quirks; it’s all handled by OpenSSH.
CONS
• One extra file to edit (but totally worth it).
────────────────────────────────────────────────
Got multiple servers? Chain them up:
Host dev
HostName dev.example.com
User alice
Host prod
HostName 10.20.30.40
User root
Port 2222
IdentityFile ~/.ssh/prod_rsa
────────────────────────────────────────────────
Quick troubleshooting checklist
────────────────────────────────────────────────
• Permissions: ~/.ssh/config must be 600 or 644; sometimes SSH refuses to read it if it’s world-writable.
• On macOS: the file path and permissions are the same.
• On Windows with WSL/OpenSSH: same syntax; file lives at ~/.ssh/config inside WSL or %USERPROFILE%\.ssh\config for cmd/PowerShell OpenSSH.
• Always put match-all settings at the top, specific blocks later.
📌 TL;DR
Add this to ~/.ssh/config, then use ssh name:
Host name
HostName domain
User user
…and you’re done. 🚀