Recent Posts
- jQuery attrAugust 12, 2021
- jQuery mouseenterAugust 9, 2021
- jQuery ToggleclassAugust 6, 2021
- jQuery attr
Introduction to SCP Command in Linux
SCP is termed as “secure copy” which allows us to secure transferring of files between localhost and remote host or between two remote hosts. It uses Secure Shell (SSH) protocol for security and authentication and security purpose on which it is based. SCP is used for it’s secured, simplified & pre-installed facility availability. In this topic, we are going to learn about SCP Command in Linux.
This command allows us to copy files from to or even between different hosts/computer files to be copied to, from, or between different hosts. It is a command-line utility that allows you to copy files & directories between two locations securely.
Purpose
We can use SCP command for the below use:
Security
As security is one of the aspects of any Linux based command and secure copy (SCP) is one of them, where both files and passwords are encrypted from the malware or even anyone trying to gain sensitive information on the traffic.
SCP Syntax
Scp command syntax takes the following form :
scp [OPTIONS] [username@][Source_HOST:]file_name1 [username@]Destination_HOST:]file_name2
where
1. OPTIONS: We have different options such as ssh configuration, cipher, limit, ssh port, recursive copy and many more.
2. [username@]Source_HOST:]file_name1: Source file with username & host.
3. [username@]Destination_HOST:]file_name2: Destination file with username & host.
Note: Absolute or relative path can also be mentioned in case of local files while remote file names need to include a username and host with “@” annotation.
Options
SCP command provides a variety of options. Let us discuss most commonly used:
Examples of SCP Command in Linux
Now let us discuss each option with different examples so that we can have a proper understanding of the SCP command concepts.
1. Copying of a file from the local system to the remote system
Let us consider, we want to copy a jdk file from our local Linux system to remote systems (172.20.11.32) by scp command then we will use the following command :
Command:
scp jdk-linux-x32.rpm root@172.20.11.32:/app
From the above output, the command will copy a file from the local system to our remote system under /app folder.
2. Copying a file from a remote system to a local system
In case there is a need to copy a file from a remote system to the local system under the /app folder then we need to execute the below command:
Command:
scp root@172.20.11.32:/root/Technical_file.txt /app
3. Copying of files with Verbose mode enabled
If we want to know what’s going behind the transfer of file then we can use verbose mode with the “-v” option.
Command:
scp -v jdk-linux-x32.rpm root@172.20.11.32:/app
From the above output, we can see how detail level information is displayed in verbose mode.
4. Transfering of multiple files to a remote system
There may be a requirement where we need to transfer multiple files in one go. So in this scp plays a vital role. By running the below command we can achieve this.
Command:
scp File_test.txt Demo_file.html jdk-linux-x32.rpm root@172.20.11.32:/app
5. Transferring files between two remote host
In order to copy files and directory between two remote hosts which from be from a local Linux system to two different remote Linux systems, below will help us to achieve this.
Command:
scp pkumar@172.20.11.33:~/backup-file.zip root@172.20.11.32:/app
ssh root@172.20.11.32 “ls -l /app/backup-file.zip” .
6. Copying of files and directory recursively (-r)
Option -r can be used to copy the files in a directory with the help of the below command recursively.
Command:
scp -r Document root@172.20.11.32:/app/
By the below command, we can verify whether the Document folder is copied to a remote system or not.
7. Increasing the file transfer speed by using compression option (-C)
To transfer the file quickly option -C can be used. This file is compressed and decompressed at the destination hosts.
Command:
scp -r -C Document root@172.20.11.32:/app
In the above, we are transferring the Document directory with the compression option enabled.
8. Limiting the bandwidth while copying of files ( -l )
By ‘-l’ option we can restrict bandwidth during file transfer. Bandwidth is measured in Kbit/s, shown by below example:
Command:
scp -l 500 jdk-linux-x32.rpm root@172.20.11.32:/app
9. Specifying different ssh port in scp command ( -P)
There may be some scenarios where ssh port gets changed on destination host so we can specify the port number using the ‘-P’ option.
Command:
scp -P 2030 jdk-linux-x32.rpm root@172.20.11.32:/app
In above ssh port for remote/destination host is ‘2030’
10. Transfer files in quiet/silent mode ( -q)
We can use the ‘-q’ option to hide the details of information and different messages.
The below command can easily do this.
Command:
scp -q -r Document root@172.20.11.32:/app/
Conclusion
In this way, we have learned about SCP command, different options, and application in the Linux environment for secure copying of data.
MCP is the right place for best computer Courses institute and advance Courses in Mohali and Chandigarh.The Complete Programming Academy can change your life – providing you with the knowledge, skills, and performance in a second language which helps you to excel in your job.You can also Contact us for 6 month industrial training institute in Mohali.