How to Use SCP Command to copy file between server and local

SCP means secure copy. This command is used to copy files between hosts. It is also known as remote file copy command. Its secure because it is using same authentication as SSH command. We will see how to copy file from server to local computer and vice versa.

Copy file from server to local computer in linux

#syntax
scp -P port username@hostname:/filepath localpath

#example
scp -P 20017 root@example.com:/var/www/html/myfile.zip /home/codextblog/Downloads/

Above command will copy myfile.zip from remote computer to your computer under Downloads directory. You can ignore port option if your server is using default port.

Copy file from local computer to server in linux

#syntax
scp localpath username@hostname:/filepath

#example
scp /home/codextblog/Downloads/mysecondfile.zip root@example.com:/var/www/html/

Above command will copy mysecondfile.zip file from your computer to remote computer under html directory.

SCP command with private key authentication

Sometimes you need a identity file, generally a private key file is required to authenticate your local machine identity. In that case you have to pass key file in your SCP command as below.

#syntax
scp -i privatekey.pem username@hostname:/filepath localpath

#example
scp -i my-ec2.pem ec2-user@example.com:/home/ec2-user/test.sql /home/codextblog/Downloads/

Want to ask a question or leave a comment?

Leave a Comment

(0 Comments)

All the comments are goes into moderation before approval. Irrelevant comment with links directly goes to spam. Your email address will not be published.

To Avoid Spam Downloads, We Want Your Email

We will send you download link right
away. Please submit form below.
SEND ME DOWNLOAD LINK
Close

Increase Your
Magento 2
Knowledge

Get Weekly Tutorial
to your Inbox
Subscribe Me
close-link
Subscribe Here