SCP (secure copy) is a command-line utility that allows you to securely copy files and directories between two locations.
The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication.
Unlike rcp or FTP, scp encrypts both the file and any passwords exchanged so that anyone snooping on the network cannot view them.
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.
The syntax for the scp command is:
scp [options] username1@source_host:directory1/filename1 username2@destination_host:directory2/filename2
Copy file from a remote host to local host SCP example:
scp username@from_host:file.txt /local/directory/
Copy file from local host to a remote host SCP example:
scp file.txt username@to_host:/remote/directory/
Copy directory from a remote host to local host SCP example:
scp -r username@from_host:/remote/directory/ /local/directory/
Copy directory from local host to a remote hos SCP example:
scp -r /local/directory/ username@to_host:/remote/directory/
Copy file from remote host to remote host SCP example:
scp username@from_host:/remote/directory/file.txt username@to_host:/remote/directory/