SCP Command Explained with Examples – Secure Copy Protocol

Introduction to SCP

Secure Copy Protocol (SCP) is a linux command-line utility that allows users to securely copy files and directories between two server connected in a network. SCP uses Secure Shell (SSH) for data transfer and uses the same mechanisms for authentication, thereby ensuring the authenticity and confidentiality.

Key pointers:

  • The scp command relies on ssh for data transfer, so it requires an ssh key or password to authenticate on the remote server
  • Colon (:) is used by scp to distinguish between local and remote path
  • To be able to copy files, user must have at least read permissions on the source file and write permission on the target path
  • While copying file be careful about the same name and location on both systems, scp will overwrite files without warning

What is the use of SCP

  • Transfering files from a local machine to a remote server
  • Transfering files from a remote server to a local local machine
  • Transferring files between from one remote server to another remote server

SCP file transfer from one machine to another over linux environment

SCP Command Syntax

Following figure shows the syntax for SCP command in general.

Following are the most common used option available with scp commands.

    • -P: Specifies the remote host ssh port.
    • -p: Preserves files modification and access times.
    • -q: Use this option if you want to suppress the progress meter and non-error messages.
    • -C: This option forces scp to compresses the data as it is sent to the destination machine.
    • -r:  This option tells scp to copy directories recursively

SCP Command Examples:

  • Copy a Local File to a Remote Server
    • scp -r  <local_file>   <remote_path>
    • scp -r   varlog.txt    techplayon@10.143.10.122:/home/user/varlog.txt
  • Copy a Remote File to a Local System
    • scp  -r  <remote_path>  <local_file>
    • scp -r  techplayon@10.143.10.122:/home/user/varlog.txt  /local/varlog.txt
  • Copy a File from one Remote Server to another Remote Server
    • scp  -r  <remoteserver#1_path>  <remoteserver#2_path>
    • scp –r  techplayon@10.143.10.122:/home/user/varlog.txt  mark@10.142.10.11:/home/mark/varlog.txt

Related Posts:

You may also like...