How to use the Linux scp command

Source: Internet
Author: User
Tags file copy ssh port number scp command secure copy

Scp is short for secure copy. scp is a secure remote file copy command based on ssh login in linux.

Syntax

Scp [-1246 BCpqrv] [-c cipher] [-F ssh_config] [-I identity_file]

[-L limit] [-o ssh_option] [-P port] [-S program]

[[User @] host1:] file1 [...] [[user @] host2:] file2

Simple syntax:

Scp [optional parameter] file_source file_target

Parameter description:

  • -1: force scp command to use protocol ssh1
  • -2: force the scp command to use the protocol ssh2
  • -4: force the scp command to only use IPv4 addressing
  • -6: force scp command to only use IPv6 addressing
  • -B: Use the batch processing mode (no transmission password or phrase is asked during transmission)
  • -C: compression is allowed. (Pass the-C flag to ssh to enable the compression function)
  • -P: retain 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: displays the output in detail mode. 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: uses cipher to encrypt data transmission. This option is 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 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: note that P is in upper case. 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.

Instance

1. Copy from local to remote

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, you need to enter the password. Only the remote directory is specified for the 1st command. The file name remains the same, and the file name is specified for the 1st command;
  • No user name is specified for the 3 and 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;

Application instance:

Scp/home/space/music/1.mp3 root@www.w3cschool.cc:/home/root/others/music

Scp/home/space/music/1.mp3 root@www.w3cschool.cc:/home/root/others/music/001.mp3

Scp/home/space/music/1.mp3 www. w3cschool. cc:/home/root/others/music

Scp/home/space/music/1.mp3 www. w3cschool. cc:/home/root/others/music/001.mp3

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, and the password needs to be entered after the command is executed;
  • 2nd user names are not specified. After the command is executed, enter the user name and password;

Application instance:

Scp-r/home/space/music/root@www.w3cschool.cc:/home/root/others/

Scp-r/home/space/music/www. w3cschool. cc:/home/root/others/

The above command copies the local music directory to the remote others directory.

2. Copy from remote to local

From remote to local, you only need to replace the last two parameters of the local command to remote, as shown in the following example:

Application instance:

Scp root@www.w3cschool.cc:/home/root/others/music/home/space/music/1.mp3

Scp-r www. w3cschool. cc:/home/root/others/home/space/music/

Description

1. If the remote server firewall has set a specified port for the scp command, we need to use the-p parameter to set the command port number. The command format is as follows:

# Scp command port 4588

Scp-p 4588 remote@www.w3cschool.cc:/usr/local/sin. sh/home/administrator

2. Use the scp command to ensure that the user has the permission to read the corresponding files on the remote server. Otherwise, the scp command will not work.

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.