English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux SCP command

Linux Command大全

The Linux SCP command is used for copying files and directories between Linux systems.

SCP is an abbreviation for secure copy, SCP is a command for secure remote file copying based on SSH login under the Linux system.

SCP is encrypted,RCP It is not encrypted, SCP is the enhanced version of RCP.

Syntax

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

Simplified notation:

scp [optional parameters] file_source file_target 

Parameter description:

  • -1: Force scp command to use protocol ssh1
  • -2: Force scp command to use protocol ssh2
  • -4: Force scp command to use IPv4Addressing
  • -6: Force scp command to use IPv6Addressing
  • -B: Use batch mode (no transmission password or phrase is asked during the transmission process)
  • -C: Allow compression. (Will-C flag is passed to ssh to enable compression function)
  • -p: Keep the original file's modification time, access time, and access permissions.
  • -q: Do not display the transmission progress bar.
  • -r: Recursively copy the entire directory.
  • -v: Display output in detail. scp and ssh(1). It will display the entire process debugging information. This information is used for debugging connections, verification, and configuration issues.
  • -c cipher: Encrypt data transmission with cipher, this option will be passed directly to ssh.
  • -F ssh_config: Specify an alternative ssh configuration file, this parameter is passed directly to ssh.
  • -i identity_file: Read the key file used for transmission from the specified file, this parameter is passed directly to ssh.
  • -l limit: Limit the bandwidth that the user can use, in Kbit/s as the unit.
  • -o ssh_option: If you are accustomed to using ssh_config(5).
  • -P port: Note that P is uppercase, port refers to the port number used for data transmission
  • -S program: Specify the program to be used for encrypted transmission. This program must be able to understand the parameter passing method in ssh(1). Options.

Online example

1、copy from local to remote

Command format:

scp local_file remote_username@remote_ip:remote_folder 
or 
scp local_file remote_username@remote_ip:remote_file 
or 
scp local_file remote_ip:remote_folder 
or 
scp local_file remote_ip:remote_file 

  • The1,2an account with a specified username requires entering a password again after the command is executed, the1A specified only the remote directory, the file name does not change, the}}2A specified file name;
  • The3,4An account without a specified username requires entering a username and password after the command is executed, the3A specified only the remote directory, the file name does not change, the}}4A specified file name;

Application Example:

scp /home/space/music/1.mp3 [email protected]:/home/root/others/music 
scp /home/space/music/1.mp3 [email protected]:/home/root/others/music/001.mp3 
scp /home/space/music/1.mp3 www.oldtoolbag.com:/home/root/others/music 
scp /home/space/music/1.mp3 www.oldtoolbag.com:/home/root/others/music/001.mp3 

Directory copy command format:

scp -r local_folder remote_username@remote_ip:remote_folder 
or 
scp -r local_folder remote_ip:remote_folder 
  • The1A command specifying a username requires entering the password again after the command is executed;
  • The2A command without specifying a username requires entering the username and password after the command is executed;

Application Example:

scp -r /home/space/music/ [email protected]:/home/root/others/ 
scp -r /home/space/music/ www.oldtoolbag.com:/home/root/others/ 

The above command copies the local music directory to the remote others directory.

2, from remote to local

To copy from remote to local, just change the order of the parameters in the command that copies from local to remote, as follows2Changing the order of the parameters, as shown in the following example

Application Example:

scp [email protected]:/home/root/others/music /home/space/music/1.mp3 
scp -r www.oldtoolbag.com:/home/root/others/ /home/space/music/

Syntax

1.If the remote server firewall has set a specific port for the scp command, we need to use -Use the P parameter to set the command port, the command format is as follows:

#scp Command Port Usage 4588
scp -P 4588 [email protected]:/usr/local/sin.sh /home/administrator

2Ensure that the user has read permissions for the corresponding files on the remote server when using the scp command, otherwise the scp command will not work.

Linux Command大全