Linux Command: scp command, linux Command scp

Source: Internet
Author: User
Tags gz file scp command secure copy

Linux Command: scp command, linux Command scp

Scp is short for secure copy. It is used to remotely copy files in Linux. Similar Commands include cp, but cp only Copies files on the local machine and cannot be copied across servers, scp transmission is encrypted. It may slightly affect the speed. When your server's hard disk changes to read-only system, scp can help you move the file out. In addition, scp does not occupy resources and does not increase the system load. At this point, rsync is far behind it. Although rsync is faster than scp, when there are many small files, rsync will lead to a very high hard disk I/O, and scp will not affect the normal use of the system.
1. Command Format:
Scp [parameter] [original path] [target path]
2. command functions:
Scp is short for secure copy. scp is a secure remote file copy command based on ssh login in linux. The scp command of linux can copy files and directories between linux servers.
3. command parameters:
-1 force scp command to use protocol ssh1
-2 force the scp command to use the Protocol ssh2
-4 force scp command to only use IPv4 addressing
-6 force scp command to only use IPv6 addressing
-B uses the batch processing mode (no transmission password or phrase is asked during transmission)
-C allows compression. (Pass the-C flag to ssh to enable the compression function)
-P retains the modification time, access time, and access permission of the original file.
-Q: The transmission progress bar is not displayed.
-R Recursively copies the entire directory.
-V details display output. Scp and ssh (1) will display the debugging information of the entire process. This information is used to debug connections, verify and configure problems.
-C cipher encrypts data transmission with cipher. This option is passed directly to ssh.
-F ssh_config specifies an alternative ssh configuration file, which is passed directly to ssh.
-I identity_file: Read the key file used for transmission from the specified file. This parameter is directly transmitted to ssh.
-L limit: limits the bandwidth that a user can use, in Kbit/s.
-O ssh_option if you are used to using the parameter transfer method in ssh_config (5,
-P port should be written in uppercase. port is the port number used for data transmission.
-S program specifies the program used for encrypted transmission. This program must be able to understand the options of ssh (1.
4. Example:
Scp command application Overview:
Copy from local server to remote server:
(1) copy a file:
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
The user name is specified for the 1st and 2nd commands. After the command is executed, enter the user password. Only the remote directory is specified for the 1st command. The file name remains the same, and the filename is specified for the 1st command.
No user name is specified for the 3 or 4 commands. After the command is executed, enter the user name and password. Only the remote directory is specified for the 3rd commands. The file name remains the same, and the file name is specified for the 4th commands.
(2) Copy directory:
Command Format:
Scp-r local_folder remote_username @ remote_ip: remote_folder
Or
Scp-r local_folder remote_ip: remote_folder
1st user names are specified. After the command is executed, enter the user password;
2nd user names are not specified. After the command is executed, enter the user name and password;

Copy from remote server to local server:
The scp command remotely replicated to the local device is the same as the command above. You only need to swap the order of the two parameters after the command locally copied to the remote device.

Instance 1: copy a file from a distance to a local directory
Command:
Scp root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz/opt/soft/
Output:

[Root @ localhost ~] # Cd/opt/soft/[root @ localhost soft] # ll total 80072drwxr-xr-x 12 root 4096 09-21 fms3.5drwxr-xr-x 3 root 4096 09-21 fms4.5drwxr- xr-x 10 root 4096 10-30 jdk1.6.0 _ 16drwxr-xr-x 10 root 4096 09-17 jdk1.6.0 _ 16. bak-rwxr-xr-x 1 root 81871260 2009-12-21 jdk-6u16-linux-x64.bindrwxrwxrwx 2 root 4096 09-21 0:16 mysqldrwxr-xr-x 3 root 4096 09-21 setup_filedrwxr-xr-x 9 root 4096 09 -17 19:at6.0.32drwxr-xr-x 9 root 4096 2012-08-14 tomcat_7.0 [root @ localhost soft] # scp root@192.168.120.204: /opt/soft/nginx-0.5.38.tar.gz/opt/soft/root@192.168.120.204's password: nginx-0.5.38.tar.gz 100% 479KB 478.7KB/s [root @ localhost soft] # ll total listen 12 root 4096 09-21 fms3.5drwxr-xr-x 3 root 4096 09-21 fms4.5drwxr- xr-x 10 root 4096 10-30 jdk1.6.0 _ 16drwxr-xr-x 10 root 4096 09-17 jdk1.6.0 _ 16. bak-rwxr-xr-x 1 root 81871260 2009-12-21 jdk-6u16-linux-x64.bindrwxrwxrwx 2 root 4096 09-21 0mysql-rw-r -- 1 root 490220 03-15 nginx-0.5.38.tar.gzdrwxr-xr-x 3 root root 4096 09-21 setup_filedrwxr-xr-x 9 root 4096 09-17 tomcat6.0.32drwxr-xr-x 9 root 4096 2012-08-14 tomcat_7.0 [root @ localhost soft] #

Note:
Download the nginx-0.5.38.tar.gz file from the/opt/soft/directory on 192.168.120.204 to the local/opt/soft/directory.

Instance 2: copy from a distance to a local device
Command:
Scp-r root@192.168.120.204:/opt/soft/mongodb/opt/soft/
Output:

[Root @ localhost soft] # ll total 80556drwxr-xr-x 12 root 4096 09-21 fms3.5drwxr-xr-x 3 root 4096 09-21 fms4.5drwxr-xr-x 10 root 4096 10-30 jdk1.6.0 _ 16drwxr-xr-x 10 root 4096 09-17 jdk1.6.0 _ 16. bak-rwxr-xr-x 1 root 81871260 2009-12-21 jdk-6u16-linux-x64.bindrwxrwxrwx 2 root 4096 09-21 0mysql-rw-r -- 1 root 490220 03-15 nginx-0.5.38.tar.gzdrwxr-xr-x 3 root root 4096 09-21 setup_filedrwxr-xr-x 9 root 4096 09-17 tomcat6.0.32drwxr-xr-x 9 root 4096 2012-08-14 tomcat_7.0 [root @ localhost soft] # scp-r root@192.168.120.204: /opt/soft/mongodb/opt/soft/root@192.168.120.204's password: mongodb-linux-i686-static-1.8.5.tgz 100% 28 MB 28.3 MB/s 00:01 README 100% 731 0.7KB/s 00:00 THIRD-PARTY-NOTICES 100% 7866 usd/s 00:00 0000100% 7753KB 7.6 MB/s 00:00 0000d 100% 7760KB 7.6 MB/s 00:01 limit export 100% 7744KB 7.6 MB/s running throughput 100% 7737KB 7.6 MB/s running program 100% 7748KB 7.6 MB/s 00:01 running stat 100% running 7.6 MB/s 00:00 mongos 100% running 5.1 MB/s 00:01 mongo 100% 3707KB 3.6 MB/s running import 100% 7754KB 7.6 MB/s running dump 100% 7773KB 7.6 MB/s 00:00 GNU-AGPL-3.0 100% 34KB 33.7KB/s 00:00 [root @ localhost soft] # ll total 80560drwxr-xr-x 12 root 4096 09-21 40 fms3.5drwxr-xr-x 3 root 4096 09 -21 fms4.5drwxr-xr-x 10 root 4096 10-30 jdk1.6.0 _ 16drwxr-xr-x 10 root 4096 09-17 jdk1.6.0 _ 16. bak-rwxr-xr-x 1 root 81871260 2009-12-21 jdk-6u16-linux-x64.bindrwxr-xr-x 3 root 4096 03-15 mongodbdrwxrwxrwx 2 root 4096 09-21 0mysql-rw-r -- 1 root root 490220 03-15 nginx-0.5.38.tar.gzdrwxr-xr-x 3 root 4096 09-21 setup_filedrwxr-xr-x 9 root 4096 09-17 tomcat6.0.32drwxr-xr-x 9 root 4096 2012-08-14 tomcat_7.0 [root @ localhost soft] #

Note:
Download the mongodb directory from/opt/soft/on the machine 192.168.120.204 to the local/opt/soft/directory.

Instance 3: upload local files to a directory specified by the remote machine
Command:
Scp/opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptest
Output:

Target directory of the target machine before uploading:
[Root @ localhost soft] # cd scptest/
[Root @ localhost scptest] # ll
Total 0
[Root @ localhost scptest] # ll

Local Machine upload:
[Root @ localhost soft] # scp/opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptest
Root@192.168.120.204's password:
Nginx-0.5.38.tar.gz 100% 479KB 478.7KB/s
[Root @ localhost soft] #

The target directory of the target machine after uploading:
[Root @ localhost scptest] # ll
Total 484
-Rw-r-1 root 490220 03-15 nginx-0.5.38.tar.gz
[Root @ localhost scptest] #
Copy code
Note:
Copy the nginx-0.5.38.tar.gz file in the local opt/soft/directory to the opt/soft/scptest directory of the remote machine 192.168.120.204.

Example 4: Upload a local directory to a directory specified by a remote machine
Command:
Scp-r/opt/soft/mongodb Co., root@192.168.120.204:/opt/soft/scptest
Output:

Target directory of the target machine before uploading: [root @ localhost ~] # Cd/opt/soft/scptest/[root @ localhost scptest] # ll total 484-rw-r -- r -- 1 root 490220 03-15 nginx-0.5.38.tar.gz [root @ localhost scptest] # Local Machine upload: [root @ localhost ~] # Scp-r/opt/soft/mongodb root@192.168.120.204:/opt/soft/scptestroot@192.168.120.204's password: mongodb-linux-i686-static-1.8.5.tgz 100% 28 MB 28.3 MB/s 00:01 README 100% 731 0.7KB/s 00:00 THIRD-PARTY-NOTICES 100% 7866 usd/s 00:00 0000100% 7753KB 7.6 MB/s 00:00 0000d 100% 7760KB 7.6 MB/s 00:01 limit export 100% 7744KB 7.6 MB/s bsondump 100% 7737KB 7.6 MB/s program files 100% 7748KB 7.6 MB/s 00:00 hour stat 100% hour 7.6 MB/s 00:01 mongos 100% hour 5.1 MB/s 00:00 mongo 100% 3707KB 3.6 MB/s hour import 100% 7754KB 7.6 MB/s 00:01 hour dump 100% 7773KB 7.6 MB/s 00:00 GNU-AGPL-3.0 100% 34KB hour/s hour [root @ localhost ~] # Target directory of the target machine after uploading: [root @ localhost scptest] # ll total 488drwxr-xr-x 3 root 4096 03-15 mongodb-rw-r -- 1 root 490220 03-15 nginx-0.5.38.tar.gz [root @ localhost scptest] #

Note:
Upload the local directory/opt/soft/mongodb to the remote machine 192.168.120.204/opt/soft/scptest directory

Related Article

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.