CommandsLinux

How to use scp (secure copy) in linux

Secure copy or SCP is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol.
Scp is generally installed by default on most linux distros as a part of openssh packages.
In this guide explain how to transfer files and folders using scp command in linux.

Example scp command syntax

The basic syntax of scp is very simple.

Copying file to host:

# scp SourceFile user@host:/home/user/TargetFile

Copy entire directory (recursively)
To copy an entire directory from one host to another use the “r” switch and specify the directory

# scp -r ~/Downloads user@host:/home/user/Downloads

When copying file from remote host to local:

# scp user@host:/home/user/file_name /home/local-username/file-name

or just download the file

# scp user@host:/home/user/file_name .

Copy files from a remote server to another remote computer:
This is really interesting and very useful, as the files copied from one server to the other, are not going to pass through your computer. The traffic is going to pass from one server to the other directly.

# scp user1@host1:/home/user1/file_name user2@host2:/home/user2/

Transfer multiple files:

When you have to copy multiple files to your remote host, the syntax is similar to the cp command:

# scp file1.txt file2.txt user@host:/home/user/

To copy multiple files from remote host to current local directory

# scp user@host:/home/user/{file1.txt,file2.txt} .

Bandwidth limit

You may limit the bandwidth used by scp command:

# scp -l 400 user@server:/home/user/* .

Where limit is specified in Kbit/s.

Connect to a different port number on remote host

If the remote server has ssh daemon running on a different port (default is 22), then you need to tell scp to use that particular port number using the ‘-P’ option.

# scp -P 4455 file.txt user@host:/home/user/file.txt

Increase scp speed:

scp uses AES-128 to encrypt data, this is very secure, but also a litle bit slow. If you need more speed and still have security, you can use Blowfish or RC4.
To increase scp speed change chipher from the default AES-128 to Blowfish

# scp -c blowfish user@server:/home/user/file .

Or use RC4 which seems to be the fastest

# scp -c arcfour user@server:/home/user/file .

Quiet mode

In quiet mode ( ‘-q’ option ), the scp output would get suppressed, and would disable the progress meter as well as warning and diagnostic messages.

$ scp -q SourceFile user@host:/home/user/TargetFile

Provide the detail information of SCP process using -v parameter

To displays debugging informatio of scp process use “-v” switch:

# scp -v SourceFile user@host:/home/user/TargetFile

That’s all. You can see man pages of scp for more detail.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close
Close