Securely copy remote files with scp


scp allows you to securely copy files locally or remotely across a network. It uses SSH for data transfer and uses the same authentication. If you do not have public key authentication enabled you will be prompted for a password.

This basic format for scp is this.

Assuming the remotehost has a username which matches username on the local host, this command will copy a a local file into the /tmp directory on remotehost. Notice that the colon separates the host from the location.

You will be presented with the real-time statistics about the file transfer.

This command is similar but the period instructs the file to be placed in the users home directory.

You can specify another user and login using their username. This will copy the file to ryan’s home directory.

Alternatively you can copy a remote file to your local host. The period in the destination path refers to the current working directory in this case.

Likewise, you can copy to any other local path you have access, such as the /tmp directory.

Copying directories is similar except that the ‘-r’ option is required. This command will copy a directory from the current working directory to the users home directory on remotehost.

You can even copy from one remote host to another.

Use the -p option to preserve modification times, access times, and modes from the original file.