Skip to main content

Module 9: Networking

Lesson 93: scp Command

In this lesson, you'll learn how to use the scp command to securely copy files and directories between local and remote Linux hosts.

SSH may be the most popular protocol to enable Linux administrators to manage the servers in a remote secure way.

Built-in with the SSH command is the scp command, that is used to copy file(s) between servers in a secure way.

scp Command Syntax

The below command will read as: copy "source_file_name" into "destination_folder" at "destination_host" using the "username" account.

scp source_file_name username@destination_host:destination_folder

scp Command Options

Option Description
-v Print debug information while copying
-p Preserve file modification and access times
-C Enable compression while copying files over the network
-c CIPHER Specify the cipher to use for encryption (e.g. 3des)
-l LIMIT Limit the bandwidth used by SCP (in Kilobits/sec)
-P PORT Specify a non-default port (capital P)
-r Copy directories recursively
-q Suppress progress meter and diagnostic messages
-F FILE Use a specific ssh_config file

The basic scp command without parameters will copy the files in the background. Users will see nothing unless the process is done or an error appears.

You can use the -v parameter to print debug information to the screen. It can help you debug connection, authentication, and configuration problems.

1. Copy a File from Local Host to Remote Server

The following command copies a file scp-cheatsheet.pdf from a local to a remote Linux system under /home/tecmint directory.

$ scp -v scp-cheatsheet.pdf [email protected]:/home/tecmint/.
Executing: program /usr/bin/ssh host 192.168.0.183, user tecmint, command scp -v -t /home/tecmint/.
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 192.168.0.183 [192.168.0.183] port 22.
debug1: Connection established.
debug1: identity file /home/tecmint/.ssh/id_rsa type -1
debug1: identity file /home/tecmint/.ssh/id_rsa-cert type -1
debug1: identity file /home/tecmint/.ssh/id_dsa type -1
debug1: identity file /home/tecmint/.ssh/id_dsa-cert type -1
debug1: identity file /home/tecmint/.ssh/id_ecdsa type -1
debug1: identity file /home/tecmint/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/tecmint/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/tecmint/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/tecmint/.ssh/id_ed25519 type -1
debug1: identity file /home/tecmint/.ssh/id_ed25519-cert type -1
debug1: identity file /home/tecmint/.ssh/id_ed25519_sk type -1
debug1: identity file /home/tecmint/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/tecmint/.ssh/id_xmss type -1
...

2. Copy a File from Remote Host to Local Host

The following command copies a file ssh-cheatsheet.pdf from a remote host to a local system under /home/tecmint directory.

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’