LinuxCommandLibrary

scp

Securely copy files between computers

TLDR

Copy a local file to a remote host

$ scp [path/to/local_file] [remote_host]:[path/to/remote_file]
copy

Use a specific port when connecting to the remote host
$ scp -P [port] [path/to/local_file] [remote_host]:[path/to/remote_file]
copy

Copy a file from a remote host to a local directory
$ scp [remote_host]:[path/to/remote_file] [path/to/local_directory]
copy

Recursively copy the contents of a directory from a remote host to a local directory
$ scp -r [remote_host]:[path/to/remote_directory] [path/to/local_directory]
copy

Copy a file between two remote hosts transferring through the local host
$ scp -3 [host1]:[path/to/remote_file] [host2]:[path/to/remote_directory]
copy

Use a specific username when connecting to the remote host
$ scp [path/to/local_file] [remote_username]@[remote_host]:[path/to/remote_directory]
copy

Use a specific SSH private key for authentication with the remote host
$ scp -i [~/.ssh/private_key] [path/to/local_file] [remote_host]:[path/to/remote_file]
copy

Use a specific proxy when connecting to the remote host
$ scp -J [proxy_username]@[proxy_host] [path/to/local_file] [remote_host]:[path/to/remote_file]
copy

SYNOPSIS

scp [options] source ... target

PARAMETERS

-r
    Recursively copy directories

-P PORT
    SSH port on remote host

-p
    Preserve modification times and modes

-q
    Quiet mode, suppress progress meter

-C
    Enable compression

-i FILE
    Identity file for public key authentication

-l LIMIT
    Limit bandwidth in Kbit/s

-o OPTION
    SSH option

-v
    Verbose mode

-3
    Copy through local host between two remotes

DESCRIPTION

scp copies files between hosts on a network using SSH for data transfer. It uses the same authentication and provides the same security as SSH. scp is being deprecated in favor of sftp and rsync, but remains widely used for simple file transfers.

CAVEATS

Deprecated in favor of sftp or rsync over SSH. Does not preserve symbolic links without special options. Large transfers may be slow compared to rsync.

PATH FORMATS

Local: /path/to/file
Remote: user@host:/path/to/file
Example: scp file.txt user@server:/home/user/

SEE ALSO

sftp(1), ssh(1), rsync(1), cp(1)

Copied to clipboard