Categories

scp command line to securely copy files over ssh, between Linux, Mac or Windows

Written by Guillermo Garron .
Date: 2012-04-25 16:59:35 -0400

Spanish version

SCP Introduction

scp stands for secure cp (copy), which means you can copy files across ssh connection. That connection will be securely encrypted, it is a very secure way to copy files between computers

You can use scp to copy files from or to a remote server. You can also copy files from one remote server to another remote server, without passing traffic through your PC.

You can use scp on Linux, Mac and Windows (using WinSCP).

SCP Usage

scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]
from-host
Is the name or IP of the host where the source file is, this can be omitted if the from-host is the host where you are actually issuing the command
user
Is the user which have the right to access the file and directory, that is supposed to be copied in the case of the from-host, and the user who has the rights to write in the to-host
source-file
Is the file or files that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory
destination-file
Is the name that the copied file is going to take in the to-host, if none is given all copied files are going to keep its names

SCP Options

-p
Preserves the modification and access times, as well as the permissions of the source-file in the destination-file
-q
Do not display the progress bar
-r
Recursive, so it copies the contents of the source-file (directory in this case) recursively
-v
Displays debugging messages

SCP Examples

scp *.txt user@remote.server.com:/home/user/

That is going to copy all files with .txt extension to the folder /home/user in the remote.server.com host

scp -r miguel@10.1.2.2:/home/miguel/ miguel@10.1.2.3:/home/miguel/

That is going to recursively copy all files from Miguel’s home directory on 10.1.2.2 to his home folder in 10.1.2.3 host.

As have been told before, scp copies files between computers using ssh, and there are three types of usage:

Copy files from a local computer to a remote computer

scp somefile username@server:/home/username/

Copy files from a remote server to your local computer

scp username@server:/home/username/file_name /home/local-username/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 user_name1@server1:/home/user_name1/file_name user_name2@server2:/home/user_name2/

SCP Tricks

Bandwidth limit

You may limit the bandwidth used by scp command

scp -l limit username@server:/home/uername/* .

Where limit is specified in Kbit/s.

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 .

This last one is not very secure, and it may not be used if security is really an issue for you. You can also increase security while decreasing speed. Everything has its cost.

scp -c 3des user@server:/home/user/file .

That is maybe the slowest, but also maybe the more secure one (I may be wrong, I’m not an expert in encryption).

Final notes

It is very important to consider that scp encrypts the data before sending it over the internet. So, if you can use it over ftp or rcp, you better use it.

Finally, as I said before, you can use WinSCP to copy to and from Windows to Linux or Mac. For the Mac OS X scp is supported by default, just like with Linux.

Comment about this post on Google+

permalink

If you enjoyed the article, please share it

twitter | facebook | google+ | linkedin | email | reddit


comments powered by Disqus

Sponsor

Bio.

My name is Guillermo Garron. I am telecommunications engineer from Bolivia

I like technology a lot, and this site is mainly dedicated to that

Social feeds

rss | twitter | email | google+

Posts via email

If you use the letter icon above and subscribe to my tinyletter newsletter, you will get one to two emails, related to this site, or not. If what you want is to get the posts of this site via email, use the form below

Enter your email address:

Delivered by FeedBurner