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.
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 targetCopy 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.tarNotes:
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.tarRecursive 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.tarThis guide demonstrates the essential usage patterns of scp for secure file transfer in Linux environments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
