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.