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.
scp username1@source_host:folder1/filename1 username2@destination_host:folder2/filename2
scp -r root@myNAS1:/home/myphotos root@myNAS2:/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 : username1@source_host:folder1/filename1
The second part of the command is the destination: username2@destination_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.
Copy the file test.txt from a remote host to a local host:
scp username@host1:/test.txt /my/path/
Copy the file test.txt from the local host to a remote host:
scp test.txt username@host1:/my/path
Copy myfolder from the local host to a remote host:
scp -r myfolder username@host1:/my/path
Copy myfolder from the local host to a remote host’s folder “linux”:
scp -r myfolder username@host1:/my/path/linux/
Copy multiple files from your host to a remote host:
scp test.txt pic.jpg username@host1:/my/path
Copy multiple files from a remote host to your host:
Copy all files from a remote host to your host:
scp -r username@host1:/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 username@host1:/some/path
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 username@somehost:/directory/
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.