Secure copying between servers via scp utility

1 min read

Useful when you need to copy files to server or get them from server.

The basic syntax is:

scp user[email protected]:/location/to/file [email protected]:/where/to/put

Copy to server

scp /file/to/send [email protected]:/where/to/put


scp ~/image.jpg [email protected]:/root/images

If you use config file for SSH you can use host names [email protected] -> serverName

scp ~/image.jpg serverName:/root/images

You can pass a custom port (22 by default) for a server connection by -P key

scp -P 22022 ~/.db [email protected]:/.db

Copy files between servers

scp [email protected]:/file/to/send [email protected]:/where/to/put

Remember: when you copy files between servers, your server remote2 (target) should have ssh public key of server remote1 (source).

Copying directories

Add -r key to copy elements recursively


scp -r ~/images [email protected]:/root/

Directory images will be created automatically.