How to use SCP

H

Secure Copy over SSH

As the name implies, SCP stands for SecureCopy and is a Linux command for copying files to and from different hosts. It does this by using the SSH protocol ensuring encryption on both filenames and the password. Unlike other protocols like FTP , the filenames or the password is not visible in case someone is snooping the network making SCP a very secure and powerful tool. By default, the SSH port is 22 therefore SCP will be using port 22. When copying files to/from another host, the account’s password will be required.

 

Syntax

scp [email protected]_host:folder1/filename1 [email protected]_host:folder2/filename2

An example:

 scp -r [email protected]:/home/myphotos [email protected]:/home/

This example is for copying the “myphotos” folder from my 1st NAS to my 2nd NAS.

The first part of the command is the source[email protected]_host:folder1/filename1

The second part of the command is the destination[email protected]_host:folder2/filename2

The -r argument is recursive which means the contents of a folder will be copied as well. Without recursive, only the empty folder or file will be copied.

Examples

Copy the file test.txt from a remote host to a local host:

 scp [email protected]:/test.txt /my/path/

Copy the file test.txt from the local host to a remote host:

 scp test.txt [email protected]:/my/path

Copy myfolder from the local host to a remote host:

 scp -r myfolder [email protected]:/my/path

Copy myfolder from the local host to a remote host’s folder “linux”:

 scp -r myfolder [email protected]:/my/path/linux/

Copy multiple files from your host to a remote host:

 scp test.txt pic.jpg [email protected]:/my/path

Copy multiple files from a remote host to your host:

 scp [email protected]:/some/path/\{test.txt,pic.jpg\}

Copy all files from a remote host to your host:

 scp -r [email protected]:/some/path* .

* is a wildcard and if present on the end of name* it will consider all the files and folders which contain “name” as the prefix.
* . means in this directory.

Copy the file test.txt from local host to remote host using port 1000:

 scp -P 1000 test.txt [email protected]:/some/path

Performance

By default, the SCP command uses Triple-DES cipher for encrypting the data. While Blowfish is different , it can increase speed by a margin.

 scp -c blowfish somefile [email protected]:/directory/

Final thoughts

SCP is a versatile tool for copying data between remote hosts and while not being the fastest way to transfer data it is surely one of the most secure ones. Be very careful when typing and watch every spacing as you might end up deleting or messing up files. The syntax is very important when issuing SCP commands.

Enjoy!

Recent Posts

Archives

Categories