A First Entry
Create or open the file on your computer:
nano ~/.ssh/configHost myserver
HostName your_server_ip
User user
Port 2222
IdentityFile ~/.ssh/id_ed25519Now connect with:
ssh myserverThis file is the client configuration. It is separate from /etc/ssh/sshd_, which configures the server.
Permissions
ssh refuses a config file that other users can write to:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/configThe Keywords You Will Use Most
Host: the short name you type. It can list several names or use wildcards such asweb-*.HostName: the real IP address or host name.User: the account on the server.Port: the SSH port, if not 22. See how to change the SSH port.IdentityFile: the private key to use for this host.IdentitiesOnly yes: offer only that key, not every key in the agent.ProxyJump: reach the server through another one.ServerAliveInterval: send a keep-alive message after that many seconds without traffic.LocalForward: open a tunnel on every connection.
One Key per Server
Host myserver
HostName your_server_ip
User user
IdentityFile ~/.ssh/work_ed25519
IdentitiesOnly yesWith many keys in the agent, a server may stop the connection before the right key is tried. IdentitiesOnly yes prevents that, one of the causes covered in Permission denied (publickey).
Through a Jump Host
When a server is reachable only through a gateway machine, describe both and let ssh chain them:
Host bastion
HostName 203.0.113.10
User deploy
Host myserver
HostName your_server_ip
User user
ProxyJump bastionssh myserver first connects to the bastion, then on to the server. Your private key stays on your computer; the bastion only passes the traffic through.
Keep Idle Sessions Open
Some routers and firewalls close connections that are quiet for a few minutes. A keep-alive prevents that:
Host *
ServerAliveInterval 60
ServerAliveCountMax 3After 60 quiet seconds the client sends a message through the encrypted channel, and it disconnects after three unanswered ones.
Forward a Port on Every Connection
If you always open the same tunnel, for example to a database that listens only on the server, put it in the host block:
Host myserver-db
HostName your_server_ip
User user
LocalForward 3307 127.0.0.1:3306ssh -N myserver-db then opens the tunnel without a shell. Port 3307 on your computer leads to the database on the server.
Split a Long File
With many servers, keep groups in separate files and include them at the top of ~/.ssh/config:
Include ~/.ssh/config.d/*Create the folder with mkdir -p ~/.ssh/config.d and put one file per project in it, with mode 600 like the main file. Place the Include line before the first Host line: an Include inside a Host block applies only to that block.
Order Matters
ssh reads the file from top to bottom and, for each setting, keeps the first value it finds for the host. Put specific hosts first and the general Host * block at the end; otherwise its values win. Options on the command line come before the file.
To see the final settings for a host without connecting, run:
ssh -G myserverOther Tools Use It Too
scp file.txt myserver:/tmp/ and sftp myserver pick up the same user, port, and key; see how to use scp. A tunnel defined with LocalForward is described in SSH tunneling and port forwarding.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations