Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
NAME
scp - secure copy

SYNOPSIS
scp [OPTION...] [[USER@]HOST1:]FROM_FILE... [[USER@]HOST2:]TO_FILE

DESCRIPTION
scp copies files between the local host and a remote host. File names may contain a user and host specification to indicate that the file is to be copied
to/from that host; current user is assumed if the user portion is omitted. Directory copy is done recursively by default. Copying files between remote hosts
is not allowed. Copying files on the local host, i.e. both from host and to host are the local host, is not supported.

...

 Directory copy is done recursively by 
default. Copying files between remote hosts is not allowed, and, copying files on the local host is not supported.

...

OPTIONS

...


scp uses SSH for data transfer, and uses the same authentication and provides the same security as SSH. scp will ask for passphrase if -i option is presented;
otherwise, it will ask for password for each distinct user and host specification.

OPTIONS
-H KNOWN_HOSTS_FILE
Set the path to the file that has the identities of all known hosts, default to user-home-directory/.ssh/known_hosts.

...


-i IDENTITY_FILE
Select the file from which the identity (private key) for RSA authentication is read.

...


-P PORT
Specify the port to connect to on the remote host, default to 22.

...


-t
Trust hosts whose identity is unknown.

EXAMPLES
Copy a local file in the working directory to a remote directory:
Code Block
scp fromFile username@hostname:~/toDirectory

For example, if you want to copy a file named users.csv to a directory called Documents on a remote computer with IP 10.72.5.100 with username aqua enter:
scp users.csv aqua@10.72.5.100:~/Documents

Copy a local file to a remote directory with a different filename:
Code Block
scp /tmp/fromFile username@hostname:/tmp/newFileName

For example, if you want to copy a file named users.csv and rename it to data.csv enter:
scp users.csv aqua@10.72.5.100:~/Documents/data.csv

  Copy local files to a remote directory:
Code Block
scp /tmp/fromFile1 /tmp/fromFile2 username@hostname:/tmp

For example, if you want to copy all sql file with extension .sql to a remove directory enter:
scp *.sql aqua@10.72.5.100:~/Documents

Copy a local directory to a remote directory, note that the /tmp/dirName directory on the remote machine needs to be created beforehand:
Code Block
scp /tmp/dirName username@hostname:/tmp/dirName

For example, to copy a local directory named csv to a remote machine enter:
scp /home/tariq/csv aqua@10.72.5.100:~/Documents

Copy a remote file to a local directory:
Code Block
scp username@hostname:/tmp/fromFile /tmp/toDirectory

For example, to copy a file from a remote host named data.log to the local machine under a folder named temp enter:
scp aqua@10.72.5.100:~/Documents/data.log temp/

Copy a remote directory to a local directory, note that the trailing asterisk after the from the directory is required in order for directory copy to work:
Code Block
scp username@hostname:/tmp/fromDirectory/* /tmp/toDirectory

For example:

...

 scp aqua@10.72.5.100:~/Documents/* temp/

Copy a local file in the working directory to a remote directory with a custom identity file use the -i option.
Code Block
scp -i IDENTITY_FILE fromFile username@hostname:~/toDirectory

For example, if you want to copy a file named users.csv to a directory called Documents on a remote computer with an identity file enter the below command.
id_rsa is the so called private key when you generate an SSH key public/private key pair.
scp -i /home/tariq/.ssh/id_rsa users.csv aqua@10.72.5.100:~/Documents

 NOTES

...


NOTES
If the destination to where file(s) to be copied is a directory, then the destination directory needs to be created before the scp command is executed;
otherwise, exception will be thrown.