Securely Transfer Files From or to a Remote Server Using SCP
How to use secure copy protocol
The SCP (secure copy protocol) is a network protocol, based on the BSD RCP protocol, that supports file transfers between hosts on a network. SCP uses secure shell (SSH) for data transfer and the same mechanisms for authentication.
Using SCP, you can copy file/directory from:
- your local machine to a remote system
- a remote system to your local system
- one remote system to another remote system from your local system
While transferring data using SCP, files and passwords are encrypted so that anyone snooping on the traffic doesn’t get anything sensitive.
Things to keep in mind before you start:
scpcommand relies on SSH for transferring the data, so it requires an SSH key or password to authenticate on the remote systems.
- To be able to copy file/directory, you must have at least read permissions on the source file and write permission on the target system.
The syntax for the
scp command is:
scp [options] username@source_host:directory/filename /where/to/put
In the examples below, I recursively copy entire directories.
From remote to local
scp -r username@ipaddress:/directory/to/send /local/where/to/put
From local to remote
scp -r /local/directory/to/send username@ipaddress:/where/to/put
Copying between two remote hosts
scp -r username@ipaddress1:/file/to/send username@ipaddress2:/where/to/put
You can use
scp with the following options according to your requirements.
scp –P port — Generally, 22 is used as the default port of
scp. You can also specify a specific port.
scp –p — An estimated time and the connection speed will appear on the screen.
scp –q — Disable progress meter and warning.
scp –r — Recursively copy entire directories.
scp –v — Print debug information into the screen. It can help you in debugging connection, authentication, and configuration problems.
scp -c — By default, SCP using AES-128 to encrypt files. If you want to change to another cipher to encrypt it, you can use
I hope that you now have understood how to make the best use of the
scp command to securely transfer files between the systems.
If you have any suggestions on your mind, please let me know in the comments. And if you know any other awesome features of the
scp command, do share with us.