SCP (secure copy) is a command-line utility that means that you can securely copy information and directories between two areas.
scp, you possibly can copy a file or listing:
- Out of your native system to a distant system.
- From a distant system to your native system.
- Between two distant techniques out of your native system.
When transferring knowledge with
scp, each the information and password are encrypted in order that anybody snooping on the site visitors doesn’t get something delicate.
On this tutorial, we’ll present you find out how to use the
scp command by means of sensible examples and detailed explanations of the most typical scp choices.
SCP Command Syntax
Earlier than going into find out how to use the
scp command, let’s begin by reviewing the fundamental syntax.
scp command syntax take the next kind:
scp [OPTION] [person@]SRC_HOST:]file1 [person@]DEST_HOST:]file2
OPTION– scp options akin to cipher, ssh configuration, ssh port, restrict, recursive copy …and so on.
[user@]SRC_HOST:]file1– Supply file.
[user@]DEST_HOST:]file2– Vacation spot file
Native information must be specified utilizing an absolute or relative path, whereas distant file names ought to embody a person and host specification.
scp offers plenty of choices that management each side of its conduct. Essentially the most broadly used choices are:
-P– Specifies the distant host ssh port.
-p– Preserves information modification and entry instances.
-q– Use this selection if you wish to suppress the progress meter and non-error messages.
-C– This selection forces
scpto compresses the info as it’s despatched to the vacation spot machine.
-r– This selection tells
scpto repeat directories recursively.
Earlier than you Start
scp command depends on
ssh for knowledge switch, so it requires an ssh key or password to authenticate on the distant techniques.
The colon (
:) is how
scp distinguish between native and distant areas.
To have the ability to copy information, you should have at the least learn permissions on the supply file and write permission on the goal system.
Watch out when copying information that share the identical identify and site on each techniques,
scp will overwrite information with out warning.
When transferring giant information, it is suggested to run the
scp command inside a display screen or tmux session.
Copy Recordsdata and Directories Between Two Programs with
Copy a Native File to a Distant System with the
To repeat a file from an area to a distant system run the next command:
$ scp file.txt email@example.com:/distant/listing
file.txt is the identify of the file we wish to copy,
remote_username is the person on the distant server,
10.10.0.2 is the server IP tackle. The
/distant/listing is the trail to the listing you wish to copy the file to. In the event you don’t specify a distant listing, the file might be copied to the distant person dwelling listing.
You may be prompted to enter the person password, and the switch course of will begin.
Output: firstname.lastname@example.org's password: file.txt 100% 0 0.0KB/s 00:00
Omitting the filename from the vacation spot location copies the file with the unique identify. If you wish to save the file beneath a unique identify, it’s worthwhile to specify the brand new file identify:
$ scp file.txt email@example.com:/distant/listing/newfilename.txt
If SSH on the distant host is listening on a port apart from the default 22 then you possibly can specify the port utilizing the
$ scp -P 2322 file.txt firstname.lastname@example.org:/distant/listing
The command to repeat a listing is very similar to as when copying information. The one distinction is that it’s worthwhile to use the
-r flag for recursive.
To repeat a listing from an area to distant system, use the
$ scp -r /native/listing email@example.com:/distant/listing
Copy a Distant File to a Native System utilizing the
To repeat a file from a distant to an area system, use the distant location as a supply and native location because the vacation spot.
For instance to repeat a file named
file.txt from a distant server with IP
10.10.0.2 run the next command:
$ scp firstname.lastname@example.org:/distant/file.txt /native/listing
In the event you haven’t set a passwordless SSH login to the distant machine, you can be requested to enter the person password.
Copy a File Between Two Distant Programs utilizing the
In contrast to
rsync , when utilizing
scp you don’t need to log in to one of many servers to switch information from one to a different distant machine.
The next command will copy the file
/information/file.txt from the distant host
host1.com to the listing
/information on the distant host
$ scp email@example.com:/information/file.txt firstname.lastname@example.org:/information
You may be prompted to enter the passwords for each distant accounts. The information might be switch immediately from one distant host to the opposite.
To route the site visitors by means of the machine on which the command is issued, use the
$ scp -3 email@example.com:/information/file.txt firstname.lastname@example.org:/information
On this tutorial, you realized find out how to use the
scp command to repeat information and directories.
You may additionally wish to arrange an SSH key-based authentication and hook up with your Linux servers with out coming into a password.
If you’re frequently connecting to the identical techniques, you possibly can simplify your workflow by defining your entire connections within the SSH config file .