Skip to Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

6.3. Copying Files Remotely

Problem

You want to copy files securely from one computer to another.

Solution

For one file:

$ scp myfile remotehost:
$ scp remotehost:myfile .

For one file, renamed:

$ scp myfile remotehost:myfilecopy
$ scp remotehost:myfile myfilecopy

For multiple files:

$ scp myfile* remotehost:
$ scp remotehost:myfile\* .

To specify another directory:

$ scp myfile* remotehost:/name/of/directory
$ scp remotehost:/name/of/directory/myfile\* .

To specify an alternate username for authentication:

$ scp myfile smith@remotehost:
$ scp smith@remotehost:myfile .

To copy a directory recursively (-r):

$ scp -r mydir remotehost:
$ scp -r remotehost:mydir .

To preserve file attributes (-p):

$ scp -p myfile* remotehost:
$ scp -p remotehost:myfile .

Discussion

The scp command has syntax very similar to that of rcp or even cp:

scp name-of-source name-of-destination

A single file may be copied to a remote file or directory. In other words, if name-of-source is a file, name-of-destination may be a file (existing or not) or a directory (which must exist).

Multiple files and directories, however, may be copied only into a directory. So, if name-of-source is two or more files, one or more directories, or a combination, then specify name-of-destination as an existing directory into which the copy will take place.

Both name-of-source and name-of-destination may have the following form, in order:

  1. The username of the account containing the file or directory, followed by “@". (Optional; permitted only ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Linux Security Cookbook - Second Edition

Practical Linux Security Cookbook - Second Edition

Tajinder Kalsi
Mastering Linux Command Line

Mastering Linux Command Line

Coding Gears | Train Your Brain

Publisher Resources

ISBN: 0596003919Errata Page