Use the scp command to transfer files between Linux Hosts

Source: Internet
Author: User
Tags scp command scp command in linux ssh port

Use the scp command to transfer files between Linux Hosts

Command: scp
Copy files between different Linux Hosts
File copy with Security, ssh-based logon.

Some linux releases do not have their own scp, so you need to install scp
# Yum-y install openssh-clients

Basic Syntax:
# Scp [parameter] source target

Common Parameters
-V: displays the progress, which can be used to view the connection, authentication, or configuration error.
-R: assign a value to the directory
-C: Enable compression options
-P: select the port
-4: Use an IPV4 address forcibly
-6: Use IPV6 addresses forcibly

Common usage:
1. Copy local data to remote data
1.1 # scp local_file remote_username @ remote_ip: remote_folder
1.2 # scp local_file remote_username @ remote_ip: remote_folder/remote_file
1.3 # scp local_file remote_ip: remote_folder
1.4 # scp local_file remote_ip: remote_folder/remote_file

1.1 and 1.2 specify the user name. After the command is executed, enter the remote server password.
No user name is specified for 1.3 and 1.4. After the command is executed, enter the user name and password of the remote server.
Only remote directories are specified in 1.1 and 1.3, and the file name remains unchanged.
1.2 and 1.4 specify the remote directory and file name

# Scp/doiido/hello. sh bkjia@
# Scp/doiido/hello. sh bkjia@ sh
# Scp/doiido/hello. sh
# Scp/doiido/hello. sh sh

2. Copy the remote data to the local device.

From remote to local, you only need to change the order of the last two parameters of the local command to remote command. Because of the same syntax, only the example is listed here;
# Scp bkjia@ sh
# Scp bkjia@ sh/doiido/newhello. sh
# Scp sh
# Scp sh/doiido/newhello. sh

3. Copy the Directory
When you need to transfer a directory, you only need to add the parameter-r, for example
# Scp-r/doiido/hello/bkjia@

4. Note:
4.1: If the remote server modifies the ssh port, scp needs to use the modified port. For example, if the ssh port of the remote server is 2222, add the-P parameter:
# Scp-p 2222/doiido/hello. sh bkjia@

4.2: Before using scp, check whether the remote connection user has the permission to read the corresponding files on the remote server. At the same time, you also need to pay attention to whether the user that executes the scp command has the permission to the local directory.

Configure scp to transfer files between Linux and Unix without a password

Cp/scp command + scp command in Linux

CentOS cannot use scp command Solution

Copy files between two Linux Hosts using scp

This article permanently updates the link address:

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