SCP is short for Secure Copy. SCP is a secure remote file copy command based on SSH login in Linux.

grammar

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...]  [[user@]host2:]file2Copy the code

Simple notation

SCP [Optional] file_source file_targetCopy the code

Parameters that

  • - 1: forces the SCP command to use protocol ssh1
  • 2 -: forces the SCP command to use protocol ssh2
  • 4 -: forces the SCP command to use IPv4 addressing only
  • - 6: forces the SCP command to use IPv6 addressing only
  • -B: Using batch mode (no transmission password or phrase is asked during transmission)
  • -C: Allows compression. (Pass the -c flag to SSH to turn on compression.)
  • -p: Preserves the modification time, access time, and access permission of the original file.
  • -q: The transfer progress bar is not displayed.
  • -r: Recursively copies the entire directory.
  • -v: Displays output in detailed mode. SCP and SSH (1) show debugging information for the entire process. This information is used to debug connection, validation, and configuration problems.
  • -c cipher: Encrypts data transmission in cipher mode. This option is directly passed to SSH.
  • -F ssh_config: Specifies an alternate SSH configuration file, which is passed directly to SSH.
  • -i identity_file: Reads the key file used for transmission from the specified file. This parameter is passed directly to SSH.
  • -l limit: Specifies the bandwidth that a user can use. The unit is Kbit/s.
  • -o ssh_option: If you are used to passing parameters in ssh_config(5),
  • -P port: Capital P, port specifies the port number used for data transmission
  • -S program: Specifies the program to use when encrypting transmission. This program must be able to understand SSH (1) options.

The instance

The command format

  • Replication from local to remote
#Specify a remote folder
scp local_file remote_username@remote_ip:remote_folder 

#Or rename the file after copying it to a remote location
scp local_file remote_username@remote_ip:remote_file 
Copy the code

Copy directory command format:

Scp-r local_folder remote_username@remote_ip:remote_folder or scp-r local_folder remote_ip:remote_folderCopy the code
  • Remote replication to local

To replicate from remote to local, you only need to switch the last two parameters of the command, as shown in the following

#Specify a remote folder
scp remote_username@remote_ip:remote_folder local_file  

#Or rename the file after copying it to a remote location
scp remote_username@remote_ip:remote_file  local_file
Copy the code

instructions

  • If the remote server firewall has specified a port for the SCP command, we need to use the -p parameter to set the port number of the command. The command format is as follows:
#The SCP command uses port 4588
scp -P 4588 [email protected]:/usr/local/sin.sh /home/administrator
Copy the code
  • When using the SCP command, ensure that the user has the permission to read the corresponding files on the remote server. Otherwise, the SCP command will not work.