The use of SCP commands in Linux systems __linux

Source: Internet
Author: User
Tags file copy file permissions scp command secure copy
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:
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
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
Instance:
Scp/home/linux/soft/scp.zip Root@www.mydomain.com:/home/linux/others/soft
Scp/home/linux/soft/scp.zip Root@www.mydomain.com:/home/linux/others/soft/scp2.zip
Scp/home/linux/soft/scp.zip Www.mydomain.com:/home/linux/others/soft
Scp/home/linux/soft/scp.zip Www.mydomain.com:/home/linux/others/soft/scp2.zip
(2) Copy directory:
Command format:
Scp-r Local_folder Remote_username@remote_ip:remote_folder
Or
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;
Example:
Scp-r/home/linux/soft/root@www.mydomain.com:/home/linux/others/
Scp-r/home/linux/soft/www.mydomain.com:/home/linux/others/
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.
For example:
SCP Root@www.mydomain.com:/home/linux/soft/scp.zip/home/linux/others/scp.zip
SCP www.mydomain.com:/home/linux/soft/-r/home/linux/others/
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 aaron@x.x.29.18:/tmp/www aaron@x.x.29.13 ' 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 root@x.x.29.18:/tmp remote machine user root root@x.x.29.18 ' 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

%/etc/init.d/sshd restart

Re-test successful ...

su ROOT before using the SCP command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.