fbpx
Skip to content

Detailed instructions on working with SCP

SCP (Secure Copy Protocol) is a protocol for copying files between remote hosts over SSH protocol. Here is a detailed instruction on how to use SCP with a lot of features.

Connect to remote host

To connect to remote host via SSH use

ssh [options] [username]@[address or hostname]

For example, to connect to the remote host 192.168.1.100 as user, run the following command:

ssh [email protected]

You will be prompted for a user password to connect to the remote host.

Copying files

Use the following command to copy a file from the local host to the remote host:

scp [options] [local file path] [username]@[address or hostname]:[path on remote host]

To copy the file /home/user/docs/file.txt to the remote host 192.168.1.100 in the /home/user/backup/ directory, run the following command

scp /home/user/docs/file.txt [email protected]:/home/user/backup/

Use the following command to copy a file from a remote host to a local host:

scp [options] [username]@[address or hostname]:[path on remote host] [path on local host]

For example, to copy the file /home/user/docs/file.txt from the remote host 192.168.1.100 to the local host in the directory /home/user/backup/, run the following command:

scp [email protected]:/home/user/docs/file.txt /home/user/backup/

If you want to copy an entire directory, use the -r option, for example:

scp -r /home/user/docs/ [email protected]:/home/user/backup/

SCP Options

SCP has many options which enhance its capabilities:

-P [port]: specifies the SSH port on the remote host to connect to

-v: display detailed debugging information about the file transfer process

-p: stores file attributes such as modification time, owner and permissions

-q: starts SCP in silent mode, without displaying any messages

-C: enables data compression during transfer

Tags: