Linux SCP Command Usage With Examples

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
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.

Ubuntu, Debian, Mint, Kali

scp is provided with the ssh package.

Fedora,CentOS, RHEL

We will use dnf or yum package manager.

OR

Scp Syntax

To get a simple and fast help run SCP without any parameter like below. As we can see we use scp command and provide options related with the connection. The we will provide username and remote host name with @ delimiter.

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 /home/aliIt is not asked for a password because I have already copied required credentials.

LEARN MORE  Linux Tmux Tutorial With Command Examples

Passwordless scp

If we want to use scp in a passwordless and more secure manner we need to setup SSH Key based authentication. In order to set up key-based authentication, we need to have keys which can be created with the ssh-keygen command like below.

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

Copy Local File To The Remote With Scp

We will copy the 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

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 a recursive parameter. Recursive parameter makes to copy entire directories recursively. We will use option.

Copy Folders Recursively With Scp

Copy Folders Recursively With Scp

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.

LEARN MORE  Linux Ssh Tunneling or Port Forwarding Local and Remote Ports with Examples?

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.

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

Passing Password To Scp

We have already set up passwordless key based authentication but we may need to use scp with the password. In this case, we can provide a password with a 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 to Escape Spaces In The Path With Scp

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

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

LEARN MORE  Windows Dir Command Tutorial With Examples To List Files and File Information

We have added a 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 faster Blowfish or aes128-ctr encryption algorithm usage will make transfers faster.

Scp Performance

Scp Performance

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

You may also like...

1 Response

  1. 30/05/2018

    […] Linux Scp Command Usage With Eamples […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Open

Enjoy this blog? Please spread the word :)