How to use SCP

SCP (Secure Copy Protocol) is a command-line utility used to securely transfer files between a local and a remote host. It utilizes SSH (Secure Shell) for data transfer and provides encryption and authentication.

Here's the basic syntax of SCP:

scp [options] source_file_name username@destination_host:destination_folder

Where,

  • options: Various options you can use with SCP
    • -P: Specifies the port number to connect to on the remote host.
    • -r: Recursively copy entire directories.
    • -p: Preserves the modification times, access times, and modes from the original file.
    • -v: Verbose mode. Shows detailed progress information.
  • source_file_name: The name of the file with the path that needs to be copied.
  • username: The username of the destination host.
  • destination_host: The IP address or hostname of the destination host.
  • destination_folder: The directory where the file should be copied on the destination machine.

Now, let's see some examples:

Copy a file from the source server to a remote server,

scp /path/to/source/file.txt username@remotehost:/path/to/destination/

Copy a directory from the source server to a remote server,

scp -r /path/to/source/directory username@remotehost:/path/to/destination/

Copy a file using a specific port,

scp -P 2222 /path/to/source/file.txt username@remotehost:/path/to/destination/

NOTE: The -P option in SCP is used to specify the port on the destination system (remote host) where the SCP server is running. By default, SCP uses port 22, which is the standard port for SSH connections. However, there might be situations where the SSH server on the remote host is configured to listen on a different port for security reasons.

These are just basic examples. SCP offers many more options for advanced usage, like compression, limiting bandwidth, and specifying private key files. You can explore these options in the SCP manual using the following command,

man scp

This concludes our topic of How to use SCP.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS