Scp to send & receive files on unix

Carvia Tech | April 13, 2020 | 1 min read | 13 views


Scp is widely used unix utility to send and receive files from remote server in a secure fashion. It support password based authentication as well as password less RSA based authentication mechanism. We can either send/receive a single file or the entire directory using single command.

To send a file from local machine to remote server using scp

To send a single file to remote server (using password)
$ scp localfile.txt user@server:/target/dir
Send a single file to server using Public Key Auth (pem file)
$ scp -i mykey.pem localfile.txt user@server:/target/dir
To send directory to remote server (using password)
$ scp -r /copy/from/dir/ user@server:/copy/to/dir

To receive a file from remote server using scp

When we want to receive a file or directory from remote server, arguments to scp command are reversed. We need to login into local machine where we want to download the files and run the below command:

Receive a single file using password
$ scp username@remote:/copy/from/file /copy/to/dir
Receive a single file using public key authentication (pem file)
$ scp -i ~/mykey.pem user@server:/copy/from/file /copy/to/file
Receive entire directory using SCP
$ scp -r username@remote:/copy/from/dir /copy/to/dir

Top articles in this category:
  1. DevOps interview questions - Basic Concepts, Microservices, Databases, AWS
  2. Basic Unix commands for every programmer
  3. Create permanent swap space in Centos 7
  4. Install and upgrade Jenkins on Ubuntu 18.04 LTS
  5. Upgrade MySQL from 5.7 to 8 on Ubuntu 18.04
  6. Install OpenJDK 11 on Ubuntu 18.04 LTS
  7. Install ElasticSearch 7 on Ubuntu 18.04


Find more on this topic:
Dev Ops image
Dev Ops

Dev Ops Automation - Ubuntu OS, Centos, MySql, MongoDB, Java, AWS Infrastructure.

Last updated 1 week ago


Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info