SSH shortcuts: the config file, and copying files with scp

The short answer: instead of always typing ssh -p 2222 -i ~/.ssh/key user@203.0.113.10, you can give the server a name in a file and type just ssh my-vps. The same name works for scp, which copies files between your computer and the server.

The config file

1 Open (or create) the file ~/.ssh/config on your computer. On Windows 10 and 11, with the OpenSSH client that comes with the system, it is C:\Users\YOUR-NAME\.ssh\config.
2 Add an entry per server:
Host my-vps
HostName 203.0.113.10
User username
Port 22
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 60
3 Connect with ssh my-vps. The HostName is the server’s address, the Port is the port (if you changed it, see How to change the SSH port without locking yourself out) and the IdentityFile is the key. To create a key, see How to create an SSH key.
4 On Linux and Mac, protect the file: chmod 600 ~/.ssh/config. SSH refuses configuration files that other users could change.

The ServerAliveInterval 60 sends a signal every minute, so an idle connection is not cut for inactivity. If your connection drops often, see also Keeping a command running after you close SSH.

Copying with scp

To Command
Send a file to the server scp site.zip my-vps:/home/username/
Bring a file from the server scp my-vps:/var/log/app.log .
Copy a whole folder scp -r folder my-vps:/home/username/
Use a different port, without the config scp -P 2222 file username@203.0.113.10:/path/
The port letter changes: ssh uses a lowercase -p, and scp uses an uppercase -P. It is the most common mistake. With the config file, you need neither.
For big copies, which may be interrupted, or to synchronise a folder, rsync resumes where it stopped and sends only what changed: see Copying files to another server with rsync. If you lost access, see I have lost SSH access to my server.

Cannot connect to the server however many shortcuts you make? Open a ticket with the SSH error message.

Open a support ticket

SEE ALSO

How to create an SSH key and log in to your VPS without a password

How to change the SSH port without locking yourself out

Copying files to another server with rsync, safely

SFTP instead of FTP: when you can, and why it is better

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from $8.40/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?