The usage of SCP command in Inux system
Note: If-bash:scp:command not found appears during use, perform yum install openssh-clients
The SCP is a secure copy abbreviation, and the SCP is a secure remote file Copy command under the Linux system based on SSH login. (Note: In the computer room maintenance, direct connection to the server to execute this command is invalid ... The SCP commands for Linux can replicate files and directories between Linux servers.
Use of the SCP command:
The SCP is used to copy files between different hosts on the network, using the SSH security protocol to transmit data, and has the same authentication mechanism as SSH to secure remote copy of files.
SCP Command basic format:
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
Parameter description of the SCP command:
-1 Mandatory SCP command use protocol SSH1
-2 Mandatory SCP command use protocol SSH2
-4 Force the SCP command to use only IPV4 addressing
-6 Force the SCP command to use only IPV6 addressing
-B Use Batch mode (transfer password or phrase not queried during transmission)
-C allows compression. (Pass the-c flag to SSH to turn on the compression feature)
-P preserves the modification time, access time, and access rights of the original file.
-Q does not display the transport progress bar.
-R recursively copies the entire directory.
-V Displays the output in verbose mode. SCP and SSH (1) will display debugging information for the entire process. This information is used to debug connections, verify, and configure problems.
-C cipher encrypts the data transfer in cipher, this option is passed directly to SSH.
-F ssh_config Specifies an alternate SSH configuration file, which is passed directly to SSH.
-I identity_file the key file used to read the transfer from the specified file, which is passed directly to SSH.
-L limit limits the bandwidth that the user can use, in kbit/s units.
If the-O ssh_option is accustomed to using parameter passing in Ssh_config (5),
-P Port Note is uppercase P, port is the port number used to specify the data transfer
-S program specifies the programs to use when encrypting the transmission. This program must be able to understand the options for SSH (1).
Practical application of SCP command
1> from the local server to the remote server
(1) Copy files:
SCP Local_file Remote_username@remote_ip:remote_folder
SCP Local_file Remote_username@remote_ip:remote_file
SCP Local_file Remote_ip:remote_folder
SCP Local_file Remote_ip:remote_file
1th, 2 specified the user name, the command needs to enter the user password, 1th only specified a remote directory, file name unchanged, 2nd specified the filename
3rd, 4 did not specify the user name, the command needs to enter the user name and password, 3rd only specified a remote directory, the file name unchanged, the 4th specified the filename
(2) Copy directory:
Scp-r Local_folder Remote_username@remote_ip:remote_folder
Scp-r Local_folder Remote_ip:remote_folder
The 1th specifies the user name, the command needs to enter the user password after execution;
The 2nd does not specify the user name, the command needs to enter the user name and password after execution;
The above command copies the local soft directory to the remote others directory, where the/home/linux/others/soft/directory will be available on the remote server after replication
2> from a remote server to a local server
The SCP command, which is replicated from remote to local, is identical to the command above, as long as the 2-parameter interchange order is made from the local copy to the remote command.
Many of the parameters in the SCP command in the Linux system are related to SSH1, and you need to see more authentic parameter information, and you can run the man SCP to see more detailed instructions in English.
=============================================================== Practice Example: Local machine: x.x.29.12 remote machine: x.x.29.18 remote machine User: Aaron asks to be The/www/xinpindao on the local machine is replicated to the remote machine's/tmp/www%scp-r/www/xinpindao firstname.lastname@example.org:/tmp/www email@example.com ' s password: Normally enter the password of the Aaron user to complete the replication. However, this replication did not succeed with the following prompts: SCP:/tmp/www/xinpindao:permission denied: Re-view the SCP command ... No problem.. Re-enter password ... No mistakes. View remote machine directory permissions ... Drwxr-xr-x 2 root root 4096 May 7 17:30 www original problem is here, this directory was later created with root user, but for Aaron, there is no write permission to change permissions%chmod 777/tmp/www Execute the above command again ... Success... Summary: When you use the SCP command for file replication, if there is a problem with file permissions, please carefully check the directory permissions, small details please note ... Practice in two cases:%scp/www/xinpindao firstname.lastname@example.org:/tmp remote machine user root email@example.com ' s password:
Permission denied, please try again. After a number of checks, finally found-to ensure the security prior to the installation of the SSH service has been turned off the root user's logon rights resolution:
To modify the SSH permissions for root, modify the/etc/ssh/sshd_config file
Permitrootlogin no change to permitrootlogin Yes
Reboot SSH Service
Re-test successful ...
su ROOT before using the SCP command