How to use SCP command

The SCP (Secure Copy) command in the command line interface:The basic syntax for the SCP command is:

scp [options] source_file [user@]host1:destination_file

The key elements are:

  • [options]: Various options you can use to customize the SCP command, such as -r for recursive copying, -C for compression, -P for specifying the port, etc.

  • source_file: The file or directory you want to copy, which can be local or on a remote host.

  • [user@]host1: The remote host you want to copy the file to, along with the username if required.

  • destination_file: The location on the remote host where you want to copy the file.

Some common examples of using SCP:

  • Copy a local file to a remote host:

      scp local_file.txt user@remote_host:/remote/directory/
    
  • Copy a remote file to the local machine:

      scp user@remote_host:/remote/file.txt /local/directory/
    
  • Copy a directory recursively from local to remote:

      scp -r local_directory/ user@remote_host:/remote/directory/
    
  • Copy between two remote hosts:

      scp user1@host1:/remote/file.txt user2@host2:/remote/directory/
    

The SCP command uses SSH for secure authentication and encryption, so you'll need to have SSH access to the remote host. You may also need to specify the SSH private key file using the -i option if you're using key-based authentication.Overall, the SCP command provides a simple and secure way to transfer files between local and remote systems over a network.

Did you find this article valuable?

Support Lizhiyu's Blog by becoming a sponsor. Any amount is appreciated!