Linux Scp Command Usage With Eamples


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.


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

Ubuntu, Debian, Mint, Kali

Fedora,CentOS, RHEL

Scp Syntax

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

Scp Syntax

Scp Syntax

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 backup.tar.gz by providing ismail user from local system 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  How To Create Proxy With 3proxy

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.

Copy Files With Scp

Copy Files With Scp

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.

Copy Folders Recursively With Scp

Up to now we have copied single files from remote. To copy folders with sub-folder can be done with recursive parameter. Recursive parameter makes to copy entire directories recursively. We will use -r option.

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. We will use -C option for compression.

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. We will provide the port name with the -P option and the port number.

LEARN MORE  How To Find External or Wan Ip Address Without Browser

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.

LEARN MORE  Linux Avahi Daemon Tutorial With Examples

Scp Performance

Scp Performance

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)