Linux scp to copy files, do not need to enter a password, linuxscp

Source: Internet
Author: User
Tags scp file scp command

Linux scp to copy files, do not need to enter a password, linuxscp

Scp is short for securecopy. 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 readonlysystem, 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 securecopy. 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.

-The ccipher uses cipher to encrypt data transmission. This option is passed directly to ssh.

-Fssh_config specifies an alternative ssh configuration file, which is passed directly to ssh.

-Iidentity_file: Read the key file used for transmission from the specified file. This parameter is directly transmitted to ssh.

-Llimit: limits the bandwidth that a user can use, in Kbit/s.

-Ossh_option: If you are used to using the parameter transfer method in ssh_config (5,

-Pport must be written in uppercase, and port is the port number used for data transmission.

-Sprogram 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:

Scplocal_fileremote_username @ remote_ip: remote_folder

Or

Scplocal_fileremote_username @ remote_ip: remote_file

Or

Scplocal_fileremote_ip: remote_folder

Or

Scplocal_fileremote_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-rlocal_folderremote_username @ remote_ip: remote_folder

Or

Scp-rlocal_folderremote_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:

Scproot@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz/opt/soft/

Instance 1: copy a file from a distance to a local directory

Command:

Scproot@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz/opt/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-rroot@192.168.120.204:/opt/soft/mongodb/opt/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.gzroot@192.168.120.204/opt/soft/scptest

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/mongodbroot@192.168.120.204:/opt/soft/scptes

You can use the SCP command to transfer files between two LINUX Hosts. You do not need to enter a password after establishing a trust relationship. Copy the ssh public key file of your local host user to the remote host user's ~ /. In the ssh/authorized_keys file, assume that the local host linux100 and remote host linux200 are run by users on the linux100 host # ssh-k
You can use the SCP command to transfer files between two LINUX Hosts. You do not need to enter a password after establishing a trust relationship.

Copy the ssh public key file of your local host user to the remote host user's ~ /. Ssh/authorized_keys File
Assume that the local host linux100 and remote host linux200
1. users in the linux100 host
Run
# Ssh-keygen-t rsa

The result is as follows:

QUOTE:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/. username/ssh/id_rsa): # Press Enter
Enter passphrase (empty for no passphrase): # Press Enter
Enter same passphrase again: # Press Enter
Your identification has been saved in/home/. username/. ssh/id_rsa.
Your public key has been saved in/home/. username/. ssh/id_rsa.pub.
The key fingerprint is:
38: 25: c1: 4d: 5d: d3: 89: bb: 46: 67: bf: 52: af: c3: 17: 0cusername @ localhost
Generating RSA keys:
Key generation complete.

Will be in the user directory ~ /. Ssh/generate two files: id_rsa, id_rsa.pub
2. Copy the id_rsa.pub file on the linux100 host to the. ssh directory under the root user home directory of the linux200 host and change it to authorized_keys.
That is:
/Root/. ssh/authorized_keys
In this way, on the linux100 host, use the scp command to copy the file to linux200 without prompting you to enter the password. You can also use the scp command on the linux100 host to copy files on linux200 to the local host. In short, you can access linux200 on linux100 without verification.
And vice versa!

NOTE: If multiple computers need to copy data to linux200, copy the content in id_rsa.pub to the authorized_keys file.

Run cat ~ /. Ssh/a. pub> ~ /. Ssh/authorized_keys append the content

3. copy a file or directory command:
Copy a file:
(1) Copy local files to remote
Scp file name username @ computer IP address or computer name: remote path
(2) remotely copy the file back to local
Scp username @ computer IP address or computer name: local path of file name
Copy directory:
(1) copy the local directory to a remote
Scp-r directory name -- User Name @ computer IP address or computer name: remote path
(2) remotely copy the directory back to local
Scp-r username @ computer IP address or computer name: directory name local path

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.