Loading...

Lab 68: SCP - Secure Copy Protocol

Transfer files securely over SSH using scp for both upload and download workflows. Practice single-file transfers and recursive directory copies to support routine backup and artifact movement between hosts.

network remote-access core

Scenario

You need to securely transfer files between local and remote systems. You will use scp to upload a file to a remote backup directory, download a remote file back to your local working directory, and then recursively copy an entire directory to the same remote location.

Operator context

scp uses SSH for transport, so it inherits SSH authentication, encryption, and host key verification. In production, prefer key-based authentication and treat host key prompts as a security checkpoint, not a formality.

Objective

  • Upload a local file to a remote host using scp.
  • Download a remote file into the current local directory.
  • Recursively copy a directory to a remote destination.

What You’ll Practice

  • Copying a file to a remote path using scp <src> user@host:<dest>.
  • Copying a file from a remote host using scp user@host:<src> <dest>.
  • Recursively copying directories with scp -r.
  • Reading transfer progress output and confirming expected paths.

Walkthrough

Step 1 : Upload testfile.txt to the remote backup directory.
Command
scp testfile.txt labuser@192.168.1.50:/home/labuser/remote_dir

This uploads the local file from your current directory to the remote path over SSH. The destination must be a valid directory or a full file path on the remote host.

testfile.txt                                 100%   12KB  120.0KB/s   00:00
Step 2 : Download remote.txt into the current local directory.
Command
scp labuser@192.168.1.50:/home/labuser/remote_dir/remote.txt .

The final . means “download into the current working directory.” This is a common pattern when pulling logs or artifacts from a remote system for review.

remote.txt                                   100%    8KB   80.0KB/s   00:00
Step 3 : Recursively copy mydir/ to the remote backup directory.
Command
scp -r mydir labuser@192.168.1.50:/home/labuser/remote_dir

The -r flag is required for directories. Without it, scp will fail because it cannot copy directory trees by default.

mydir/file1.txt                              100%    1KB   10.0KB/s   00:00
mydir/file2.txt                              100%    1KB   10.0KB/s   00:00

Reference

  • scp <src> user@host:<dest> : Copies a local file to a remote host over SSH.
  • scp user@host:<src> <dest> : Copies a file from a remote host to a local destination.
  • scp -r <dir> user@host:<dest> : Recursively copies a directory to a remote host.
  • user@host: : The SSH target format used by both ssh and scp (user and hostname/IP).
  • . : In file transfer commands, represents the current working directory.