Summary of scp related commands

scp Cross-machine remote copy
scp is short for secure copy. It is used to remotely copy files under Linux. Commands similar to it have cp, but cp only copies locally and cannot cross servers, and scp transmission is encrypted. . When your server hard disk becomes a read only system, using scp can help you move files out.

annotation

A similar tool is rsync; scp consumes less resources and does not increase the system load much, at this point, rsync is far behind it. rsync is a little faster than scp, but when there are many small files, rsync will cause the hard disk I/O to be very high, and scp basically does not affect the normal use of the system.

 

Command format:
scp [parameter] [original path] [target path]

 

 Command parameters:
-1 Force the scp command to use the protocol ssh1
-2 Force the scp command to use the 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 (not during transmission ask for a passphrase or phrase)
-C Enable compression. (Pass the -C flag to ssh to turn on compression)
-p Keep the modification time, access time and access rights of the original file.
-q Do not display the transfer progress bar.
-r Recursively copies entire directories.
-v Display output in verbose mode. scp and ssh(1) will display debug information for the entire process. This information is used to debug connection, authentication and configuration issues.
-c cipher Encrypt data transmission with cipher, this option will be passed directly to ssh.
-F ssh_config Specifies an alternative ssh configuration file, this parameter is passed directly to ssh.
-i identity_file Read the key file used during transfer from the specified file, this parameter is passed directly to ssh.
-l limit Limit the bandwidth that users can use, in Kbit/s.
-o ssh_option If you are accustomed to using the parameter transmission method in ssh_config(5),
-P port note that the uppercase P is used, and port is the port number used for specifying data transmission.
-S program specifies the program used for encrypted transmission. This program must be able to understand the options of ssh(1).

 

Summary: Instructions for use



Copy files from local server to remote server :

$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
specifies the user name, and the user password is required after the command is executed; if the user name is not specified, after the command is executed Username and password are required;

Copy directory:

$scp -r local_folder remote_username@remote_ip:remote_folder
$scp -r local_folder remote_ip:remote_folder
The first one specifies the user name, and the user password is required after the command is executed; the second one does not specify the user name, and the user name and password are required after the command is executed. ;

annotation

The scp command to copy from the remote to the local is the same as the above command, as long as the two parameters after the command to copy from the local to the remote are swapped in order.

Example
1: Copy files from remote to local directory
$scp [email protected]:/opt/soft/demo.tar /opt/soft/
Instructions: From the directory of /opt/soft/ on the 10.6.159.147 machine Download the demo.tar file to the local /opt/soft/ directory

Example 2: Copy from remote to local
$scp -r [email protected]:/opt/soft/test /opt/soft/
Description: Download the test directory from /opt/soft/ on the 10.6.159.147 machine to the local to the /opt/soft/ directory.

Example 3: Upload a local file to the specified directory on the remote machine
$scp /opt/soft/demo.tar [email protected]:/opt/soft/scptest
Description: Copy the file demo.tar in the local opt/soft/ directory to the remote opt/soft/scptest directory of machine 10.6.159.147

Example 4: Upload the local directory to the specified directory on the remote machine
$scp -r /opt/soft/test [email protected]:/opt/soft/scptest
Description: Upload the local directory /opt/soft/test to the remote machine 10.6.159.147 on the /opt/soft/scptest directory

 

----------------------------------------

Take the Vue packaged dist directory as an example:

Enter the file path scp index.html linux username@IP address:/opt/view/dataAnalysisPlatform/
Enter the file path (submit files and files in the folder) scp -r static linux username@IP address:/opt/view/dataAnalysisPlatform /

--------------------------------------- 


Notes for copying files from server to local:

scp linux username@server IP: The path of the file to be downloaded is stored in the local path of the server.
This method is only applicable to the Linux system with the SCP function enabled.

Copy (copy the local file to the remote server)
scp -r local path /file [email protected]:/tmp #userName is the user name of the remote server, followed by the server address, /tmp is a certain remote server Directory, sometimes there will be permission problems, you can consider copying it to /tmp first, log in to the remote service, and then perform cp or mv. After pressing Enter, enter the login password of the current user of the remote server to log in.

If you specify a copy of the remote server port number, the command is
scp -r -P 2230 local path/file [email protected]:/tmp
#where 2230 after -P (uppercase) is the specified port number

Log in to the remote server:
ssh [email protected] #userName is the user name of the remote server, followed by the server address. After pressing Enter, enter the login password of the current user of the remote server to log in.

Backup
zip -r dirName.zip dirName #First, pack the backup of the files that need to be updated into a zip

Unzip
unzip shell.zip #If the __MACOSX directory is generated

remove
rm -rf fileName

Remote view/control (with UI interface)
needs to open remote management, open method: System Preferences -> Sharing Click to open remote management
, enter in the Safari address of the local system browser:
vnc://192.168.xxx.xx

In addition to scp, you can also use filezilla
window similar to wscp

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324929286&siteId=291194637