Scp send & receive files on unix

Carvia Tech | July 13, 2020 | 1 min read | 31 views


Scp is widely used unix utility to send and receive files from remote server in a secure fashion. It supports 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

Login to your local machine from where you want to send file from. Then, run the below commands.

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

To receive a file or directory from remote server, arguments to scp command are reversed. You need to login into local machine where you 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. Permanent swap space in Ubuntu
  4. Install and upgrade Jenkins on Ubuntu 18.04 LTS
  5. Install Erlang and Rabbitmq on Ubuntu 18
  6. Install Redis on Ubuntu 20.04 LTS
  7. Install OpenJDK 11 on Ubuntu 18.04 LTS


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