How To Ubuntu Linux

scp Command In Linux Example : How To Use SCP Commands To Securely Transfer Files

scp Command In Linux Example : How To Use SCP Commands To Securely Transfer Files
Written by itsubuntu

SCP is a protocol for securely transferring files between a local host and a remote host, or between two remote hosts. It is based on the Secure Shell (SSH) protocol. “SCP” refers to the Secure Copy Protocol. SCP or Secure copy protocol is easy to use and is included by default in most Linux and Unix distributions.

scp Command In Linux Example

Basic Syntax of SCP Command

Syntax:

scp [option] [[user@]host1:]file1 [[user@]host2:]file2

Options:

  • Option: [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program]
  • [[user@]host1:]file1: Source file
  • [[user@]host2:]file2: Destination

The most commonly used options with SCP command:

  • -C:  By using this option, compression will be enabled and transfer speed will be increased,
  • -c <cipher>:f you want to change the cipher, you need to use the -c option followed by the cipher name. By default, SCP uses ‘AES-128’ for the encryption of files. I
  • i <identity_file>: i stands for identify file or private key.
  • -l <limit>: l stands for limit bandwidth.
  • -B: This is used for using batch mode while copying.
  • -P <port>: You need to specifically mention the port number by using the -P option If the ssh port number of the destination host is different than the default port number 22.
  • -q: This option will execute the SCP command in quiet mode.
  • -r:  This option is used to copy the files and directories recursively.
  • -S <program>: This option in SCP is used for specifying the program to use for connecting.

Simple syntax for SCP command is mentioned below:

scp sourcefilename username@destinationhost:destinationfolder

SCP command examples

Scp command to copy a file from localhost to a remote host SCP example:

scp [options] SourceFileName UserName@TargetHost:TargetPath
scp filetocopy.txt remote_hostusername@remoteserverip:/remote/directory

Scp command to copy a file from remote host to localhostSCP example:

scp [options] UserName@SourceHost:SourceFilePath TargetFileName
scp remote_username@serverip:/remote/filetocopy.txt /local/directory

Scp command to copy a file from one remote host to another remote host:

scp [options] UserName@SourceHost:SourcePath UserName@TargetHost:TargetPath
scp user1@host1.com:/files/filetocopy.txt user2@host2.com:/files

Scp command to copy multiple files from one remote host to another remote host:

scp filename1 filename2 UserName@TargetHost:TargetDirectoryPath

Scp command to copy multiple files from remote host to the localhost:

scp userName@SourceHost:SourceDirectoryPath{filename1, filename2}

I hope that you learned some of the basic ideas of SCP commands in Linux.

About the author

itsubuntu

Leave a Comment