File transfer between remote VPS and local using SCP command

1 What is SCP

scp is secure copy, which is used for remote file copying. Data transmission uses ssh, and uses the same authentication method as ssh, providing the same security guarantee. scp will ask you for a password or passphrase when authentication is required.

2 Actual operation

2.1 Download the VPS files (directories) to the local

Suppose you need to download a file on the VPS to the local, the file path is /root/test.log, the IP address of 12.34.56.78the VPS is, the account name of the VPS is root, and the SSH port is 6666. We will download this file to the local, /Users/admin/root/test.logand we will discuss it in two cases. .

2.1.1 Use account password to connect to VPS

Then the scp command we need to execute is

scp -P 6666 [email protected]:/root/test.log /Users/admin/root/test.log

scp supports operations on entire directories, such as downloading the above root directory to the local

scp -P 6666 [email protected]:/root /Users/admin/root

After executing the scp command, you need to enter the password of the corresponding account on the VPS

2.1.2 Use .pem certificate to connect to VPS

The command to download a single file is

scp -i /Users/admin/example.pem [email protected]:/root/test.log /Users/admin/root/test.log

Remember to change the address of the .pem certificate to your own.

The command to download the entire directory is:

scp -i /Users/admin/example.pem [email protected]:/root /Users/admin/root

2.2 Upload local files (directories) to VPS

Suppose a local file needs to be uploaded to the VPS, the path of the local file is /Users/admin/root/test.log, the IP address of 12.34.56.78the VPS is, the account name of the VPS is root, and the SSH port is 6666. We upload this file to the VPS, and we will /root/test.logdiscuss it in two cases.

2.2.1 Use account password to connect to VPS

Then the scp command we need to execute is

scp -r -P 6666 /Users/admin/root/test.log [email protected]:/root/test.log

In the same way, you can also upload the entire directory

scp -r -P 6666 /Users/admin/root [email protected]:/root

2.1.2 Use .pem certificate to connect to VPS

The command to upload a single file is

scp -r -i /Users/admin/example.pem /Users/admin/root/test.log [email protected]:/root/test.log

The command to upload the entire directory is:

scp -r -i /Users/admin/example.pem /Users/admin/root [email protected]:/root

3 possible problems

  • The connection authentication fails because the SSH key is not generated locally

The content of this article is partly borrowed from http://celerysoft.github.io/2016-07-07.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324425732&siteId=291194637