How to copy files and directories between Linux hosts with scp

In this how to we will go over scp copy command and how it can be used to securely copy files between Linux hosts.
SCP uses SSH for data transfer and also uses it for authentication. By default SCP works on port 22 which is default ssh port. For security reasons it is recommended to change it to something different.

SCP works grate for situations where no NFS or SMB protocols are deployed or Firewall is in place blocking this connections. Also it becomes very useful to copy files over internet connections because it is much more secure then ftp for example.

 

In this tutorial we will be using port 222 . If your port stays default just ignore -P switch.

Assumptions

Remote file – FR1

Local directory – DL1

Remote directory – DR1

SSH Port – 222

Local system – H1

Remote system – H2

Remote user – John

Using scp between Linux hosts
Copy file from remote host to localhost:

scp -P 222 -c blowfish john@H2:/home/FR1 /local/directory

Copy directory from remote host to localhost:

scp -P 222 -c blowfish -r john@H2:/DR1 /local/directory

Copy file From localhost to remote host:

scp -P 222 -c blowfish FL1 john@H2:/remote/directory

Copy directory From localhost to remote host:

scp -P 222 -c blowfish -r DL1  john@H2:/remote/directory

Please note! -P is optional and only used to specify port , -c is also optional and only used to change encryption level. If -c not specified Triple-DES will be used.