EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

SCP Command in Linux

Home » Software Development » Software Development Tutorials » Linux Tutorial » SCP Command in Linux

SCP Command in Linux

Introduction to SCP Command in Linux

SCP is termed as “secure copy” which allows us to secure transferring of files between localhost and remote host or between two remote hosts. It uses Secure Shell (SSH) protocol for security and authentication and security purpose on which it is based. SCP is used for it’s secured, simplified & pre-installed facility availability. In this topic, we are going to learn about SCP Command in Linux.

This command allows us to copy files from to or even between different hosts/computer files to be copied to, from, or between different hosts. It is a command-line utility that allows you to copy files & directories between two locations securely.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Purpose

We can use SCP command for the below use:

  • From our local systems to a remote system or host.
  • From a remote system or server or host to our local system.
  • Among two or more remote systems from our local system.

Security

As security is one of the aspects of any Linux based command and secure copy (SCP) is one of them, where both files and passwords are encrypted from the malware or even anyone trying to gain sensitive information on the traffic.

SCP Syntax

Scp command syntax takes the following form :

scp [OPTIONS] [username@][Source_HOST:]file_name1 [username@]Destination_HOST:]file_name2

where

1. OPTIONS: We have different options such as ssh configuration, cipher, limit, ssh port, recursive copy and many more.

2. [username@]Source_HOST:]file_name1: Source file with username & host.

3. [username@]Destination_HOST:]file_name2: Destination file with username & host.

Note: Absolute or relative path can also be mentioned in case of local files while remote file names need to include a username and host with “@” annotation.

Options

SCP command provides a variety of options. Let us discuss most commonly used:

  • scp –P port: It Specify the port by which one can connect on the remote host.
  • scp –p: This option is used to check access times, modification times and different modes from the original file.
  • scp –q:  This option is used to disable the progress done by the file while copying.
  • scp –r: This option is used to recursively copy the files present in the entire directory.
  • scp –S program: This option is used for encrypted connection with the name of the program, for which the program must understand the ssh(1) option.
  • scp –v: This option will enable the command in verbose mode. So when we run the command with these options about the progress with different messages. This is helpful in authentication, debugging connection & configuration problems.
  • scp  -C: This option will enable the compression of files while copying, which increases the performance in file transfer.
  • scp -i: This is option is used to file whether its a private key or a file.

Examples of SCP Command in Linux

Now let us discuss each option with different examples so that we can have a proper understanding of the SCP command concepts.

Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,653 ratings)
Course Price

View Course

Related Courses
Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

1. Copying of a file from the local system to the remote system

Let us consider, we want to copy a jdk file from our local Linux system to remote systems (172.20.11.32) by scp command then we will use the following command :

Command:

scp jdk-linux-x32.rpm root@172.20.11.32:/app

Output:

SCP Command in Linux output 1

From the above output, the command will copy a file from the local system to our remote system under /app folder.

2. Copying a file from a remote system to a local system

In case there is a need to copy a file from a remote system to the local system under the /app folder then we need to execute the below command:

Command:

scp root@172.20.11.32:/root/Technical_file.txt /app

Output:

SCP Command in Linux output 2

3. Copying of files with Verbose mode enabled

If we want to know what’s going behind the transfer of file then we can use verbose mode with the “-v” option.

Command:

scp -v jdk-linux-x32.rpm root@172.20.11.32:/app

Output:

SCP Command in Linux output 3

From the above output, we can see how detail level information is displayed in verbose mode.

4. Transfering of  multiple files to a remote system

There may be a requirement where we need to transfer multiple files in one go. So in this scp plays a vital role. By running the below command we can achieve this.

Command:

scp File_test.txt Demo_file.html jdk-linux-x32.rpm root@172.20.11.32:/app

Output:

output 4

5. Transferring files between two remote host

In order to copy files and directory between two remote hosts which from be from a local Linux system to two different remote Linux systems, below will help us to achieve this.

Command:

scp pkumar@172.20.11.33:~/backup-file.zip root@172.20.11.32:/app
ssh root@172.20.11.32 "ls -l /app/backup-file.zip" .

Output:

output 5

6. Copying of  files and directory  recursively (-r)

Option -r can be used to copy the files in a directory with the help of the below command recursively.

Command:

scp -r Document root@172.20.11.32:/app/

By the below command, we can verify whether the Document folder is copied to a remote system or not.

Output:

output 6

7. Increasing the file transfer speed by using compression option (-C)

To transfer the file quickly option -C can be used. This file is compressed and decompressed at the destination hosts.

Command:

scp -r -C Document root@172.20.11.32:/app

In the above, we are transferring the Document directory with the compression option enabled.

8. Limiting the bandwidth while copying of files ( -l )

By ‘-l’ option we can restrict bandwidth during file transfer. Bandwidth is measured in Kbit/s, shown by below example:

Command:

scp -l 500 jdk-linux-x32.rpm  root@172.20.11.32:/app

9. Specifying  different ssh port in scp command ( -P)

There may be some scenarios where ssh port gets changed on destination host so we can specify the port number using the ‘-P’ option.

Command:

scp -P 2030 jdk-linux-x32.rpm  root@172.20.11.32:/app

In above ssh port for remote/destination host is ‘2030’

10. Transfer files in quiet/silent mode ( -q)

We can use the ‘-q’ option to hide the details of information and different messages.
The below command can easily do this.

Command:

scp -q -r Document root@172.20.11.32:/app/

Conclusion

In this way, we have learned about SCP command, different options, and application in the Linux environment for secure copying of data.

Recommended Articles

This is a guide to SCP Command in Linux. Here we discuss the basic concept, different examples along with the output to understand the SCP command concepts. You may also have a look at the following articles to learn more –

  1. Zip Command in Linux
  2. CAT Command in Linux
  3. Tar Command in Linux
  4. NFS in Linux

Linux Training Program (16 Courses, 3+ Projects)

16 Online Courses

3 Hands-on Projects

160+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Linux Training Program (16 Courses, 3+ Projects) Learn More