SCP (secure copy) is a command-line utility that allows you to securely copy files and directories between two locations.
With scp, you can copy a file or directory:
From your local system to a remote system.
From a remote system to your local system.
Between two remote systems from your local system.
When transferring data with scp, both the files and password are encrypted so that anyone snooping on the traffic doesn’t get anything sensitive.
Note
The scp command relies on ssh for data transfer, so it requires an ssh key or password to authenticate on the remote systems.
How to use scp
# syntax local copy to remotescp<OPTIONS><LOCALFILE><REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY># syntax remote to localscp<OPTIONS><USER@HOST:/PATH/TO/FILEORDIRECTORY><LOCALFILE>##### examples without parametersscpmichel@172.16.15.129:/tmp/test.txt./test.txt# copy to local directoryscpmichel@172.16.15.129:/tmp/test.txt/Users/michel/Desktop/test.txt# copy to directory /Users/michel/Desktop/scp./test.txtmichel@172.16.15.129:/tmp/test.txt# copy to remote directoryscp/Users/michel/Desktop/test.txtmichel@172.16.15.129:/tmp/test.txt# copy to remote directory ##### examples with parametersscp -P <PORT> file.txt <REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY> # the -P specifies the port if it differs from port 22
scp -P <PORT> <REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY> file.txt # the -P specifies the port if it differs from port 22
scp-r<LOCALDIRECTORY><REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY># the -r copies a directory recursivescp-r<REMOTEUSER@HOST:/PATH/TO/FILEORDIRECTORY><LOCALDIRECTORY># the -r copies a directory recursive