Skip to content
Master Secure File Transfers with scp: A Step‑by‑Step Guide
Operations 5 min read

Master Secure File Transfers with scp: A Step‑by‑Step Guide

Learn how to securely copy files between local and remote machines using the scp command, covering basic syntax, authentication options, copying to and from remote hosts, recursive directory transfers, and transferring between two remote servers, all illustrated with practical examples.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations

The scp command transfers files between a local system and a remote server (or between two remote servers) over SSH, providing encrypted transmission and supporting both password‑based and key‑based authentication.

Basic Syntax

scp source target

Copy a Local File to a Remote Server

[student@servera ~]$ scp log.tar root@serverb:/logbackup
The authenticity of host 'serverb (172.25.250.11)' can't be established.
ECDSA key fingerprint is SHA256:BCd8VCfEpGbUo3zb1De0hd1Q5nOMEzYNpMFu5o7j4Fg.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'serverb,172.25.250.11' (ECDSA) to the list of known hosts.
root@serverb's password:
log.tar                               100%   11MB   20.8MB/s   00:00
[student@servera ~]$ ssh root@serverb "ls /logbackup"
root@serverb's password:
log.tar

Notes:

Specifying root@ is optional; if omitted, the current local user is used. The user must have appropriate permissions on the remote directory.

On first connection, SSH shows a security prompt; answer yes to proceed, as scp is part of OpenSSH.

Copy a Remote File to the Local Machine

[student@servera ~]$ scp root@serverb:/logbackup/log.tar backup/
root@serverb's password:
log.tar                               100%   11MB   25.5MB/s   00:00
[student@servera ~]$ ls backup/
log.tar

Recursive Copy of Directories

Use the -r option to copy entire directories recursively.

[student@servera ~]$ scp -r root@serverb:/var/log/ backup/
root@serverb's password:
... (list of files transferred) ...

Copy Between Two Remote Hosts

[student@workstation ~]$ scp student@servera:/home/student/log.tar student@serverb:/home/student/
student@serverb's password:
log.tar                               100%   670KB   19.6MB/s   00:00
Connection to servera closed.
[student@workstation ~]$ ssh student@serverb "ls -l"
total 672
-rw-rw-r--. 1 student student 686080 Nov 6 20:54 log.tar

This guide demonstrates the essential usage patterns of scp for secure file transfer in Linux environments.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxcommand-lineSSHfile transferscp
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.