How to use "SCP" command

ann perkins

The scp command is used to copy files from host to host using the Secure Shell network protocol (or SSH protocol). SCP stands for Secure Copy.

The scp command is intended to use on Linux environment and you will need a terminal program to run it. If your computer is running on any Linux distribution such as Mac OS X, Ubuntu or Mint Linux the Terminal program is already available. If you're on Windows then you can download Putty and use it via GUI interface.

The scp command is similar to the cp command on Linux, the difference is scp command will allow to transfer files between different hosts while the cp only allows copy files in a single host.

The scp command to help to do the following tasks:

  • Copy (or upload) files from your local computer to remote host
  • Copy (or download) files from remote host to your local computer
  • Copy (or download) files from remote host A to remote host B

Copy (Upload) Files From Local Host to Remote Host

The following command will copy an image located at ~/Download/ folder on your local computer to the /home/john/images/folder on remote host with IP address 123.111.71.172:

$ scp ~/Download/sample_image.jpg john@123.111.71.172:/home/john/images/ 

Upload a file to server actually means to add this file on server. Therefore, server needs to know under which user will perform this action. That's why we need to pass the username john in the above command. After hitting Enter, you're prompted to enter password for john. If you enter the right password and hit Enter the upload process will begin.

Copy (Download) Files From Remote Host to Local Host

The following command will copy an image located at /home/john/images/ folder from remote host with IP address 123.111.71.172 to ~/Download/ folder on your local machine:

$ scp john@123.111.71.172:/home/john/images/  ~/Download/sample_image.jpg

You will also be asked for enterning password for john on remote host.

Copy Files From Remote Host to Another Remote Host

If you want to copy files from remote host A to remote host B from your local machine you can do it with scp command to. The following command will copy the sample_image.jpgfrom remote host with IP address 123.111.71.172 to another remote host with IP address 115.102.21.152.

$ scp john@123.111.71.172:/home/john/images/sample_image.jpg smith@115.102.21.152:/home/smith/images/

Reply