TrumanWong

scp

Encrypted copy of files between local host and remote host

Supplementary instructions

scp command is a command used to copy files remotely under Linux. A similar command is cp, but cp only copies locally and cannot cross servers, and scp transmission is encrypted. It might affect the speed a little bit. When your server hard disk becomes a read-only system, use scp to help you move the files out. In addition, scp does not occupy resources and does not increase the system load much. In this regard, rsync is far behind it. Although rsync is faster than scp, when there are many small files, rsync will cause very high hard disk I/O, while scp basically does not affect the normal use of the system.

grammar

scp(options)(parameters)

Options

-1: Use ssh protocol version 1;
-2: Use ssh protocol version 2;
-4: Use ipv4;
-6: Use ipv6;
-B: Run in batch mode;
-C: Use compression;
-F: Specify ssh configuration file;
-i: identity_file reads the key file used for transmission from the specified file (such as Amazon cloud pem), this parameter is passed directly to ssh;
-l: Specify bandwidth limit;
-o: Specify the ssh option to use;
-P: Specify the port number of the remote host;
-p: Keep the last modification time, last access time and permission mode of the file;
-q: Do not display copy progress;
-r: Copy recursively.

Parameters

  • Source file: Specify the source file to be copied.
  • Target file: Target file. The format is user@host:filename (the filename is the name of the target file).

Example

The scp command to copy from the remote to the local is the same as the above command. Just exchange the order of the two parameters after the command to copy from the local to the remote.

Copy files from remote machine to local directory

scp root@10.10.10.10:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/

Download the nginx-0.5.38.tar.gz file from the /opt/soft/ directory on the 10.10.10.10 machine to the local /opt/soft/ directory.

Copy OpenVPN from Amazon Cloud to local directory

scp -i amazon.pem ubuntu@10.10.10.10:/usr/local/openvpn_as/etc/exe/openvpn-connect-2.1.3.110.dmg openvpn-connect-2.1.3.110.dmg

Download the openvpn installation file from the 10.10.10.10 machine to the current local directory.

Copy from remote machine to local

scp -r root@10.10.10.10:/opt/soft/mongodb /opt/soft/

Download the mongodb directory from /opt/soft/ on the 10.10.10.10 machine to the local /opt/soft/ directory.

Upload local files to the specified directory on the remote machine

scp /opt/soft/nginx-0.5.38.tar.gz root@10.10.10.10:/opt/soft/scptest
#Specify port 2222
scp -rp -P 2222 /opt/soft/nginx-0.5.38.tar.gz root@10.10.10.10:/opt/soft/scptest

Copy the file nginx-0.5.38.tar.gz in the local /opt/soft/ directory to the opt/soft/scptest directory on the remote machine 10.10.10.10.

Upload the local directory to the specified directory on the remote machine

scp -r /opt/soft/mongodb root@10.10.10.10:/opt/soft/scptest

Upload the local directory /opt/soft/mongodb to the directory /opt/soft/scptest on the remote machine 10.10.10.10.