Detailed description of Linux commands scp transfers files between linux Hosts

Source: Internet
Author: User
Tags scp command ssh port

Detailed description of Linux commands scp transfers files between linux Hosts
Command: scp
Copy files between different linux Hosts
File copy with Security, ssh-based logon.

Some linux releases do not have their own scp, so you need to install scp
# Yum-y install openssh-clients

Basic Syntax:
# Scp [parameter] source target

Common Parameters
-V: displays the progress, which can be used to view the connection, authentication, or configuration error.
-R: assign a value to the directory
-C: Enable compression options
-P: select the port
-4: Use an IPV4 address forcibly
-6: Use IPV6 addresses forcibly

Common usage:
1. Copy local data to remote data
1.1 # scp local_file remote_username @ remote_ip: remote_folder
1.2 # scp local_file remote_username @ remote_ip: remote_folder/remote_file
1.3 # scp local_file remote_ip: remote_folder
1.4 # scp local_file remote_ip: remote_folder/remote_file

1.1 and 1.2 specify the user name. After the command is executed, enter the remote server password.
No user name is specified for 1.3 and 1.4. After the command is executed, enter the user name and password of the remote server.
Only remote directories are specified in 1.1 and 1.3, and the file name remains unchanged.
1.2 and 1.4 specify the remote directory and file name

Example:
# Scp/doiido/hello. sh dodo@192.168.100.2:/doiido
# Scp/doiido/hello. sh dodo@192.168.100.2:/doiido/newhello. sh
# Scp/doiido/hello. sh 192.168.100.2:/doiido
# Scp/doiido/hello. sh 192.168.100.2:/doiido/newhello. sh

2. Copy the remote data to the local device.

From remote to local, you only need to change the order of the last two parameters of the local command to remote command. Because of the same syntax, only the example is listed here;
# Scp dodo@192.168.100.2:/doiido/hello. sh
# Scp dodo@192.168.100.2:/doiido/hello. sh/doiido/newhello. sh
# Scp 192.168.100.2:/doiido/hello. sh
# Scp 192.168.100.2:/doiido/hello. sh/doiido/newhello. sh
3. Copy the Directory
When you need to transfer a directory, you only need to add the parameter-r, for example
# Scp-r/doiido/hello/dodo@192.168.100.2:/doiido/
4. Note:
4.1: If the remote server modifies the ssh port, scp needs to use the modified port. For example, if the ssh port of the remote server is 2222, add the-P parameter:
# Scp-p 2222/doiido/hello. sh dodo@192.168.100.2:/doiido

4.2: Before using scp, check whether the remote connection user has the permission to read the corresponding files on the remote server. At the same time, you also need to pay attention to whether the user that executes the scp command has the permission to the local directory.




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.