HomeLinuxSCP Linux Command – Securely Switch Recordsdata in Linux

SCP Linux Command – Securely Switch Recordsdata in Linux


Linux directors ought to be acquainted with the command-line atmosphere. Since GUI (Graphical Person Interface) mode in Linux servers is just not frequent to be put in.

SSH will be the hottest protocol to allow Linux directors to handle the servers in a distant safe approach. In-built with SSH command there’s SCP command, which is used to copy file(s) between servers in a safe approach.

Primary Syntax of SCP Command

The under command will learn as copy “source_file_name” into “destination_folder” at “destination_host” utilizing the “username” account.

scp source_file_name [email protected]_host:destination_folder

There are various parameters within the SCP command that you need to use. Listed below are the parameters that will use on day by day foundation utilization.

Securely Switch Recordsdata in Linux

The fundamental SCP command with out parameters will copy the information within the background. Customers will see nothing except the method is completed or some error seems.

You should use the “-v” parameter to print debug data into the display. It might probably assist you debug connection, authentication, and configuration issues.

Copy File From Native Host to Distant Server

The next command copies a file “scp-cheatsheet.pdf” from a neighborhood to a distant Linux system underneath /house/tecmint listing.

$ scp -v scp-cheatsheet.pdf [email protected]:/house/tecmint/.

Pattern Output:

SCP – Copy File to Distant Linux Server

Executing: program /usr/bin/ssh host 192.168.0.183, consumer tecmint, command scp -v -t /house/tecmint/.
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020
debug1: Studying configuration information /and so forth/ssh/ssh_config
debug1: /and so forth/ssh/ssh_config line 19: embody /and so forth/ssh/ssh_config.d/*.conf matched no information
debug1: /and so forth/ssh/ssh_config line 21: Making use of choices for *
debug1: Connecting to 192.168.0.183 [192.168.0.183] port 22.
debug1: Connection established.
debug1: id file /house/tecmint/.ssh/id_rsa sort -1
debug1: id file /house/tecmint/.ssh/id_rsa-cert sort -1
debug1: id file /house/tecmint/.ssh/id_dsa sort -1
debug1: id file /house/tecmint/.ssh/id_dsa-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa_sk sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa_sk-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ed25519 sort -1
debug1: id file /house/tecmint/.ssh/id_ed25519-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ed25519_sk sort -1
debug1: id file /house/tecmint/.ssh/id_ed25519_sk-cert sort -1
debug1: id file /house/tecmint/.ssh/id_xmss sort -1
...

Copy File From Distant Host to Native Host

The next command copies a file “ssh-cheatsheet.pdf” from a distant host to a neighborhood system underneath /house/tecmint listing.

$ scp -v [email protected]:/house/ravi/ssh-cheatsheet.pdf /house/tecmint/.

Pattern Output:

SCP – Copy File to Native System

Executing: program /usr/bin/ssh host 192.168.0.183, consumer tecmint, command scp -v -f /house/ravi/ssh-cheatsheet.pdf
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020
debug1: Studying configuration information /and so forth/ssh/ssh_config
debug1: /and so forth/ssh/ssh_config line 19: embody /and so forth/ssh/ssh_config.d/*.conf matched no information
debug1: /and so forth/ssh/ssh_config line 21: Making use of choices for *
debug1: Connecting to 192.168.0.183 [192.168.0.183] port 22.
debug1: Connection established.
debug1: id file /house/tecmint/.ssh/id_rsa sort -1
debug1: id file /house/tecmint/.ssh/id_rsa-cert sort -1
debug1: id file /house/tecmint/.ssh/id_dsa sort -1
debug1: id file /house/tecmint/.ssh/id_dsa-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa_sk sort -1
debug1: id file /house/tecmint/.ssh/id_ecdsa_sk-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ed25519 sort -1
debug1: id file /house/tecmint/.ssh/id_ed25519-cert sort -1
debug1: id file /house/tecmint/.ssh/id_ed25519_sk sort -1
...

Copy File From Distant Host to One other Host

The next command copies a file “ssh-cheatsheet.pdf” from a distant host to a different distant host system underneath /house/tecmint listing.

$ scp -v [email protected]:/house/ravi/ssh-cheatsheet.pdf [email protected]:/house/anusha/.

Copy Recordsdata with Authentic Creation Date and Time

The “-p” parameter will protect information’ unique modification and entry occasions whereas copying information together with the estimated time and the connection velocity will seem on the display.

$ scp -p scp-cheatsheet.pdf [email protected]:/house/tecmint/.

Pattern Output:

SCP – Protect File Timestamps

[email protected]'s password: 
scp-cheatsheet.pdf                                                                                                                                                                 100%  531   721.4KB/s   00:00    

Scp Compression Whereas Copying Recordsdata

One of many parameters that may quicker your file switch is the “-C” parameter, which is used to compress your information on the go. The distinctive factor is that compression solely occurs within the community. When the file has arrived on the vacation spot server, will probably be returning to the unique measurement as earlier than the compression occurred.

Check out these instructions. It’s utilizing a single file of 93 Mb.

$ scp -pv messages.log [email protected]:.

Pattern Output:

SCP Transfers File With out Compression

Executing: program /usr/bin/ssh host 202.x.x.x, consumer mrarianto, command scp -v -p -t.
OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 Could 2012
debug1: Studying configuration information /and so forth/ssh/ssh_config
debug1: /and so forth/ssh/ssh_config line 19: Making use of choices for *
debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.
debug1: Connection established.
debug1: id file /house/pungki/.ssh/id_rsa sort -1
debug1: Discovered key in /house/pungki/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature appropriate
debug1: Attempting non-public key: /house/pungki/.ssh/id_rsa
debug1: Subsequent authentication technique: password
[email protected]'s password:
debug1: Authentication succeeded (password).
Authenticated to 202.x.x.x ([202.x.x.x]:22).
debug1: Sending command: scp -v -p -t.
File mtime 1323853868 atime 1380425711
Sending file timestamps: T1323853868 0 1380425711 0
messages.log 100% 93MB 58.6KB/s 27:05
Transferred: despatched 97614832, obtained 25976 bytes, in 1661.3 seconds
Bytes per second: despatched 58758.4, obtained 15.6
debug1: Exit standing 0

Copying information with out the “-C” parameter will end in 1661.3 seconds. You could examine the consequence to the command under utilizing the “-C" parameter.

$ scp -Cpv messages.log [email protected]:.

Pattern Output:

SCP – Transfers File with Compression

Executing: program /usr/bin/ssh host 202.x.x.x, consumer mrarianto, command scp -v -p -t.
OpenSSH_6.0p1 Debian-3, OpenSSL 1.0.1c 10 Could 2012
debug1: Studying configuration information /and so forth/ssh/ssh_config
debug1: /and so forth/ssh/ssh_config line 19: Making use of choices for *
debug1: Connecting to 202.x.x.x [202.x.x.x] port 22.
debug1: Connection established.
debug1: id file /house/pungki/.ssh/id_rsa sort -1
debug1: Host '202.x.x.x' is thought and matches the RSA host key.
debug1: Discovered key in /house/pungki/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature appropriate
debug1: Subsequent authentication technique: publickey
debug1: Attempting non-public key: /house/pungki/.ssh/id_rsa
debug1: Subsequent authentication technique: password
[email protected]'s password:
debug1: Enabling compression at stage 6.
debug1: Authentication succeeded (password).
Authenticated to 202.x.x.x ([202.x.x.x]:22).
debug1: channel 0: new [client-session]
debug1: Sending command: scp -v -p -t .
File mtime 1323853868 atime 1380428748
Sending file timestamps: T1323853868 0 1380428748 0
Sink: T1323853868 0 1380428748 0
Sending file modes: C0600 97517300 messages.log
messages.log 100% 93MB 602.7KB/s 02:38
Transferred: despatched 8905840, obtained 15768 bytes, in 162.5 seconds
Bytes per second: despatched 54813.9, obtained 97.0
debug1: Exit standing 0
debug1: compress outgoing: uncooked information 97571111, compressed 8806191, issue 0.09
debug1: compress incoming: uncooked information 7885, compressed 3821, issue 0.48

As you may see, if you end up utilizing compression, the switch course of is completed in 162.5 seconds. It’s 10 occasions quicker than not utilizing the “-C” parameter. In case you are copying a number of information throughout the community, the “-C” parameter would assist you to lower the overall time you want.

The factor that we must always discover is that the compression technique won’t work on any information. When the supply file is already compressed, you’ll not discover any enchancment there. Recordsdata corresponding to .zip, .rar, footage, and .iso information won’t be affected by the “-C” parameter.

Change SCP Cipher to Encrypt Recordsdata

By default, SCP makes use of “AES-128” to encrypt information. If you wish to change to a different cipher to encrypt it, you need to use the “-c” parameter.

Check out this command.

$ scp -c 3des Label.pdf [email protected]:.

[email protected]'s password:
Label.pdf 100% 3672KB 282.5KB/s 00:13

The above command tells SCP to make use of the 3des algorithm to encrypt the file. Please watch out that this parameter utilizing “-c” not “-C“.

Limiting Bandwidth Utilization with SCP Command

One other parameter which may be helpful is the “-l” parameter. The “-l” parameter will restrict the bandwidth to make use of. Will probably be helpful in case you do an automation script to repeat a number of information, however you don’t need the bandwidth to be drained by the SCP course of.

$ scp -l 400 Label.pdf [email protected]:.

[email protected]'s password:
Label.pdf 100% 3672KB 50.3KB/s 01:13

The 400 worth behind the “-l” parameter is imply that we restrict the bandwidth for the SCP course of to solely 50 KB/sec.

One factor to recollect is that bandwidth is laid out in Kilobits/sec (kbps). It signifies that 8 bits are equal to 1 byte.

Whereas SCP counts in Kilobyte/sec (KB/s). So if you wish to restrict your bandwidth to an SCP most of solely 50 KB/s, it’s worthwhile to set it to 50 x 8 = 400.

SCP with a Completely different Port

Often, SCP is utilizing port 22 as a default port, however for safety causes, you might change the port to a different port. For instance, we’re utilizing port 2249.

Then the command ought to be like this.

$ scp -P 2249 Label.pdf [email protected]:.

[email protected]'s password:
Label.pdf 100% 3672KB 262.3KB/s 00:14

Guarantee that it makes use of a capital “P” not “p” since “p” is already used for preserved occasions and modes.

SCP – Copy Recordsdata and Directories Recursively

Typically we have to copy the listing and all information/directories inside it. Will probably be higher if we will do it in a single command utilizing the “-r” parameter, which copies all the listing recursively.

$ scp -r paperwork [email protected]:.

[email protected]'s password:
Label.pdf 100% 3672KB 282.5KB/s 00:13
scp.txt 100% 10KB 9.8KB/s 00:00

When the copy course of is completed, on the vacation spot server one can find a listing named “paperwork” with all its information. The folder “paperwork” is robotically created.

SCP – Disable Progress Messages

Should you select to not see the progress meter and warning / diagnostic messages from SCP, you might disable it utilizing the “-q” parameter. Right here’s an instance.

$ scp -q Label.pdf [email protected]:.

[email protected]'s password:
[email protected] ~/Paperwork $

As you may see, after you enter the password, there isn’t any details about the SCP course of. After the method is full, you will notice a immediate once more.

SCP – Copy Recordsdata Utilizing Proxy

The proxy server is often used within the workplace atmosphere. Natively, SCP is just not a proxy configured. When your atmosphere utilizing a proxy, it’s important to “inform” SCP to speak with the proxy.

Right here’s the situation. The proxy tackle is 10.0.96.6 and the proxy port is 8080. The proxy additionally applied consumer authentication. First, it’s worthwhile to create the “~/.ssh/config” file. Second, you place this command inside it.

ProxyCommand /usr/bin/corkscrew 10.0.96.6 8080 %h %p ~/.ssh/proxyauth

Then it’s worthwhile to create the file “~/.ssh/proxyauth” which incorporates.

myusername:mypassword

After that, you are able to do SCP transparently as normal.

Please discover that the corkscrew is won’t be put in but in your system. On my Linux Mint, I would like to put in it first, utilizing the usual Linux Mint set up process.

$ apt-get set up corkscrew

For different yum-based techniques, customers can set up corkscrew utilizing the next yum command.

# yum set up corkscrew

One other factor is that for the reason that “~/.ssh/proxyauth” file incorporates your “username” and “password” in clear-text format, please guarantee that the file could be accessed by you solely.

Select a Completely different ssh_config File

For cellular customers who typically change between the corporate networks and public networks, will probably be struggling to all the time change settings in SCP. It’s higher if we will put a distinct ssh_config file to match our wants.

Proxy is used within the firm community however not within the public community and also you often change networks.

$ scp -F /house/pungki/proxy_ssh_config Label.pdf

[email protected]:.
[email protected]'s password:
Label.pdf 100% 3672KB 282.5KB/s 00:13

By default “ssh_config” file per consumer will likely be positioned in “~/.ssh/config“. Creating a selected “ssh_config” file with proxy compatibility will make it simpler to change between networks.

If you end up on the corporate community, you need to use the “-F” parameter. If you end up on a public community, you may skip the “-F” parameter.

That’s all about SCP. You’ll be able to see man pages of SCP for extra element. Please be at liberty to go away feedback and solutions.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments