Instead of typing ssh -p 2222 -i ~/.ssh/id_ed25519 alex@203.0.113.10 every time, you can write these details once into a small file on your computer and then just type ssh myserver. The short name also works for scp, sftp and rsync. Tested with OpenSSH on Linux; macOS and the OpenSSH client of Windows use the same file.
1. The File
The file is called config and lives in the folder .ssh in your home folder:
- Linux and macOS:
~/.ssh/config - Windows:
C:\Users\YourName\.ssh\config(without an extension)
Create it if it does not exist. On Linux and macOS, make it private: chmod 600 ~/.ssh/config.
2. One Block per Server
Host myserver
HostName 203.0.113.10
User alex
Port 22
IdentityFile ~/.ssh/id_ed25519
Host apphosting
HostName ds12345.seedhost.eu
User username
- Host: the short name you choose.
- HostName: the real address or IP of the server.
- User: your user name on that server.
- Port: only needed if SSH does not use port 22, for example after Change the SSH Port of Your Linux Server.
- IdentityFile: only needed for a key with a special name; see Log In to Your Linux Server With an SSH Key.
3. Use the Short Name
ssh myserver scp holiday.jpg myserver:/srv/photos/ sftp apphosting rsync -a --progress ~/Music/ myserver:/srv/music/
The same short name works with ssh, scp, sftp and rsync. To see which settings SSH really uses for a name, run ssh -G myserver; it lists hostname, user, port and identityfile among many others.
Handy Extras
- A tunnel that opens with every login: add
LocalForward 8099 127.0.0.1:8099to the block. More in Open a Web Page That Listens Only on Your Server: SSH Tunnel. - A connection that does not drop when idle: add
ServerAliveInterval 60.