SCP(secure copy) is a command-line utility
that allows you to securely copy files and directories between two locations.
- We can use it in the following situations
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 scp command relies on ssh for data transfer
so it requires an ssh key or password to authenticate on the remote systems.
The colon(:) is how scp distinguish between local and remote locations.
To be able to copy files
you must have at least read permissions on the source file
and write permission on the target system.
Be careful when copying files that share the same name and location on both systems
scp will overwrite files without warning.
When transferring large files
When transferring data with scp
both the files and password are encrypted
so that anyone snooping on the traffic doesn’t get anything sensitive.
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
scp provides a number of options that control every aspect of its behavior.
The most widely used options are:
-P : Specifies the remote host ssh port. -p : Preserves files modification and access times. -q : Use this option if you want to suppress the progress meter and non-error messages. -C : This option forces scp to compresses the data as it is sent to the destination machine. -r : This option tells scp to copy directories recursively.
Local to Remote
- To copy a file from a local to a remote system run the following command:
$ scp file.txt firstname.lastname@example.org:/remote/directory
Saving a file with a different name
$ scp file.txt email@example.com:/remote/directory/newfilename.txt
Specifying Server Port
If SSH on the remote host is listening on a port other than the default 22
then you can specify the port using the -P argument:
$ scp -P 1234 file.txt firstname.lastname@example.org:/remote/directory
The command to copy a directory is much like as when copying files.
The only difference is that you need to use the -r flag for recursive.
$ scp -r /local/directory email@example.com:/remote/directory
Remote to Local
$ scp firstname.lastname@example.org:/remote/file.txt /local/directory
Remote to Remote
$ scp email@example.com:/files/file.txt firstname.lastname@example.org:/files
We looked at how to use scp cli
Let’s use it well.