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.
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.
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.
scp.
scp <src> user@host:<dest>.
scp user@host:<src> <dest>.
scp -r.
testfile.txt to the remote backup
directory.
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
remote.txt into the current local
directory.
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
mydir/ to the remote backup
directory.
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
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.