Scp stands for secure copy and its means of securely transferring files between two machines on a network. It is a file transfer network protocol. SCP uses Secure Shell (SSH) mechanisms for data transfer and authentication to ensure the confidentiality of the data in transfer one side to another side.
Why use Scp?
You can copy a file or directory from one machine to another machine or local machine to virtual machine:
- From your local system to a remote system.
- From a remote system to your local system.
When you transfer the data, SCP both the files and password are encrypted format.
How Does Scp Work?
The SCP client can easily upload files to an SSH server or request files and directories for downloading. Then, the server sends all the subdirectories and the files that are available for download. it is in fact a native command in most operating systems, such as macOS, Windows, or Linux.
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2 [user@]SRC_HOST:]file1 - Source file. [user@]DEST_HOST:]file2 - Destination file
Local files should be specified using an absolute path while remote file names should include a user and host.
scp provides a number of options that control every aspect of its behaviour. The most widely used options are:
-P– Specifies the remote host ssh port.
-p– Preserves files modification and access times.
-C– This option forces
scpto compress the data as it is sent to the destination machine.
- – r – This option tells Scp us to copy directories recursively.
- -J – destination
- -l – limit
- -o – ssh_option
Before you Start:
scp command based on
ssh for moving data one machine to another machine, so it requires an ssh key or password to authenticate on the remote systems.
In copy files, you must have at least read permissions on the source file and write permission on the target or destination system.
Importanat point to copy files that share the same name and location on both systems,
scp will overwrite files without warning.
Copy Files Between two systems using SCP:
To copy a file from a local system to a remote system using the following command:
scp -i ec2.pem demo.txt email@example.com:/home/ubuntu/myfiles
- -i – identity_file
- demo.txt – text file
- firstname.lastname@example.org – Remote server Public IP address
- /home/ubuntu/myfiles – Destination Path
Transfer file server to local machine:
Transfer a file from server to local firstly you add the public key (.pem) file.
ssh-add ec2.pem Add the publickey (.pem) identity
And then Demo.txt file transfer from server to the local machine.
scp email@example.com:/home/ubuntu/demo.txt .
- firstname.lastname@example.org – Remote machine IP address(Public IP).
- /home/ubuntu/demo.txt – Remote machine file path
- (.) – local machine current Directory
Advantages of Scp:
- it is faster than SFTP.
- it maintains the Security of the data being transferred and protects the authenticity by blocking packet sniffers from extracting valuable information from the data packets.
Disadvantage of Scp:
- It is not as complete a process as other protocols. It can only transfer a file.
- It is slower than it should be, especially on high bandwidth networks.