LinuxTutorial2 min read

How to Transfer Files Between Linux Servers with SCP

Transfer files securely between Linux servers using SCP — practical examples for uploading, downloading, and copying entire directories over SSH.

Developer terminal on a laptop in low light

What Is SCP?

SCP (Secure Copy Protocol) copies files over an SSH connection. If you can SSH into a server, you can SCP files to and from it. No additional software is needed — SCP is included with OpenSSH, which comes pre-installed on most Linux systems.

Basic Syntax

scp [options] source destination

Remote paths use the format: user@host:/path/to/file

Upload a File to a Server

# Copy local file to remote server
scp report.pdf alice@192.168.1.50:/home/alice/documents/

# Specify a remote directory
scp config.txt deploy@myserver.com:/etc/myapp/

Download a File from a Server

# Copy remote file to local current directory
scp alice@192.168.1.50:/var/log/app.log .

# Save with a different name
scp alice@192.168.1.50:/var/log/app.log ~/Downloads/app-backup.log

Copy an Entire Directory

Use -r for recursive directory copies:

scp -r ~/projects/my-app alice@192.168.1.50:/home/alice/
scp -r alice@server.com:/var/www/html ./website-backup/

Useful Options

  • -r — recursive (copy directories)
  • -P 2222 — use a non-default SSH port (capital P)
  • -i ~/.ssh/id_ed25519 — specify an SSH key
  • -C — enable compression (useful for large text files)
  • -v — verbose mode for debugging

Use a Non-Standard SSH Port

scp -P 2222 file.txt alice@server.com:/home/alice/

Note: for SCP, the port flag is uppercase -P; for SSH it's lowercase -p.

Copy Between Two Remote Servers

scp alice@server1.com:/data/file.txt bob@server2.com:/backup/

Alternatives to SCP

  • rsync — better for large transfers; only copies changed files. Use rsync -avz -e ssh src/ user@host:/dst/
  • SFTP — interactive file transfer over SSH. Run sftp user@host for a shell-like interface

Common Issues

  • Permission denied — check the destination directory is writable by the remote user
  • Host key verification failed — run ssh-keygen -R hostname to clear a stale host key
  • Wrong port — don't forget -P if the server doesn't use port 22