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

scp -P port username@hostname:/filepath localpath

scp -P 20017 /home/codextblog/Downloads/

Above command will copy 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

scp localpath username@hostname:/filepath

scp /home/codextblog/Downloads/

Above command will copy 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.

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

scp -i my-ec2.pem /home/codextblog/Downloads/

Want to ask a question or leave a comment?

Leave a Comment


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.

Increase Your
Magento 2

Get Weekly Tutorial
to your Inbox
Subscribe Me
Subscribe Here