Secure remote file copy

Here’s a quick description of the scp command used for securely copying files between systems on Linux and UNIX.

The scp (secure copy) command can be used to copy files or even entire directories to a remote host. scp is a replacement for the rcp (remote copy) command. While rcp provides the same functionality it is not encrypted and therefore not secure. The scp command uses SSH for data transfer, providing SSH level security.

scp takes arguments in the form of scp –options source destination. The most common option is the –r (recursive) option which is necessary if you are using scp on multiple files or on directories. The source and destination arguments can specify not only a path but optionally a username and hostname in the format of username@hostname:path. If the username is omitted scp assumes the username of the current logged in user. If the hostname is omitted scp assumes the path provided is on the current system. Typically either the source or the destination will describe a remote system; however you could use scp to move a file or files from one remote system to another.

The following example copies the file secret.dat from user tclark’s home directory to a directory named /backup/tclark on a server named backup_server logging in as user terry. As indicated below, the scp command will prompt for the password for user terry on the backup_server when the connection is attempted.

$ scp /home/tclark/secret.dat terry@backup_server:/backup/tclark
terry@backup_server's password: password
secret.dat 100% 1011 27.6KB/s 00:00

Zach has a good article about setting up ssh with key authentication which will allow you to use the scp and ssh commands without a password while still maintaining security.

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!

linux, unix, system administration, sysadmin, easy linux, scp