Linux Scp Command Usage With Eamples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-scp-command-usage-with-eamples/
PINTEREST
PINTEREST
INSTAGRAM

What is Scp? Scp is acronym for Secure Copy. It is used primarily for copying files over ssh connection. The copied files are encrypted and assumed secure as ssh. If the files contains sensitive data copying them with scp or similar encrypted protocol is the best solution. In this tutorial we will look how to use scp in a detailed manner.

Install

Scp is provided by ssh packages in linux distributions. So to install scp we will install ssh but ssh is generally installed by default.

Scp Syntax

To get a simple and fast help run scp without any parameter like below.

Man Scp

To get more detailed help man scp command can be used like below. Scp Unix usage is not different from Linux Scp usage.

Man Scp
Man Scp

Copy Files With Scp

We will copy files scp. While copying files scp will ask for credentials.

We have copied original-ks.cfg by providing root user from localhost to the current directory withIt is not asked for a password because I have already copied required credentials.

Copy Ssh Credentials

We will create a key pair.

After creating key pair we will deplot public key with the following command to the remote system by providing user. It will ask password for the user. After deployment we can use ssh without password.

LEARN MORE  Dymerge Dictionary Merge Tool

Copy Local File To The Remote With Scp

We will copy local file to the remote. As you will see there is no difference from copying from remote to local.

Ok there is no problem. original-ks.config is local file and path but /root/original-ks.config is the remote file and path. In root@localhost root is the user and localhost is the server.

LEARN MORE  Linux Sshd Server Configuration and Security Options With Examples

Copy Folders Recursively With Scp

Up to now we have copied single files from remote. To copy folders with subfolder can be done with recursive parameter. Recursive parameter makes to copy entire directories recursively.

Compress Files While Copying With Scp

Scp encrypts files while copying and this makes some performance loss for the transmission. We can eliminate this performance loss by compressing files. Keep in mind that files are compressed for transfer not entirely.

By providing -C parameter we have enabled compression for the transfer.

Use Different Ssh Port For Scp

Ssh runs by default tcp/22 but sometimes it may be different from that. Scp assumes the port of ssh 22 too. We can change port like below.

LEARN MORE  How To Install and Use Cygwin With Terminal and Ssh Examples

We have provided port number with -P parameter and the value 2222 .

Passing Password To Scp

We have already setup passwordless key based authentication but we may need to use scp with password. In this case we can provide password with simple app named sshpass to the scp like below.

We have installed it. Because it is separate from ssh tools.

Here -p for the password and “123456” is our password. Note that our password is not strong and it is easily hackable. Then we provide regular scp command.

How Escape Spaces In The Path With Scp

If there is spaces in the local or remote path it may become problem. Say we have a folder named test 1 . There is  two solution for this

We have simple add \\ before space in the folder name.

We have added single and double quote around path like above.

Scp Performance

As we know scp uses some encryption algorithms. Scp by default uses Triple-DES to encrypt network traffic. Triple-DES can cause some performance bottlenecks so more fast Blowfish or aes128-ctr
encryption algorithm usage will make transfers faster.

Scp Performance
Scp Performance
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-scp-command-usage-with-eamples/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.