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 username@source:/location/to/file username@destination:/where/to/put

Copy to server

scp /file/to/send username@remote:/where/to/put

Example:

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 root@remote:/.db

Copy files between servers

scp username@remote1:/file/to/send username@remote2:/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

Example:

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

Directory images will be created automatically.