Skip to content

Linux basicsFor beginnersDuration around 5 min.

The scp command with examples: copy files over SSH

scp copies files over an SSH connection โ€” encrypted, with the same credentials as your login, and without an additional service on the server. This guide shows the commands for common use cases, each with an example to copy.

Tested on with OpenSSH 9.6 on Ubuntu 24.04 LTS and OpenSSH 10.2 on Ubuntu 26.04 LTS

At a glance

  • The format is always scp source destination; you write a destination on a server as user@address:path.
  • -r copies folders, -P selects a different SSH port (capital P), -i a specific key.
  • Since OpenSSH 9.0, scp transfers via the SFTP protocol; -O switches back to the legacy method for older remote hosts.

Prerequisites

  • A server you can log into via SSH โ€” such as a VPS or a Cloud Server. Nothing more than the SSH service needs to be running on the server for this.
  • The OpenSSH client on your machine: it is included in Linux and macOS, and in Windows 10 and 11 it is part of the system and available in PowerShell.

In the examples, the user is user and the server is 203.0.113.10. Replace both with your details; a hostname can also be used instead of the address.

Upload a file to the server

First the source on your machine, then the destination on the server. The colon separates the server and path; if the path ends with a slash, the file keeps its name.

Upload
scp report.pdf user@203.0.113.10:/home/user/

Download a file from the server

Conversely, the server comes first. The dot at the end is the current directory on your machine.

Download
scp user@203.0.113.10:/home/user/backup.tar.gz .

Copy a folder

For a folder and its contents, you need -r. /home/user/project is created on the server with all subfolders.

Copy a folder recursively
scp -r project user@203.0.113.10:/home/user/

Different port or specific key

If SSH does not listen on port 22, specify the port with a capital -P โ€” unlike ssh, which takes a lowercase -p. With -i you select a specific private key.

Port and key
scp -P 2222 report.pdf user@203.0.113.10:~/
scp -i ~/.ssh/id_ed25519 report.pdf user@203.0.113.10:~/

Timestamps, compression, and bandwidth

-p preserves the modification time and permissions of the source. -C compresses in transit, which noticeably helps with text and logs, but barely with archives. -l limits the bandwidth in kilobits per second โ€” 8000 is roughly 1 MB per second.

Additional options
scp -p report.pdf user@203.0.113.10:~/
scp -C -l 8000 backup.tar.gz user@203.0.113.10:~/

Multiple files with a wildcard

An asterisk on the server side must be enclosed in quotation marks. Otherwise, your own shell will try to resolve it before scp starts.

Fetch all .log files from a folder
scp 'user@203.0.113.10:~/logs/*.log' .

Copy from server to server

scp can copy between two servers. With -3, the data flows through your machine โ€” the servers then do not need access to each other, only you need access to both.

Between two servers
scp -3 user@203.0.113.10:~/backup.tar.gz user@203.0.113.20:~/

scp, SFTP, and the legacy protocol

Since OpenSSH 9.0, scp transfers via SFTP; Ubuntu 24.04 includes OpenSSH 9.6, Ubuntu 26.04 OpenSSH 10.2. The commands do not change for you. Only a very old remote host without SFTP requires the legacy method, which is enabled by -O:

Force legacy scp protocol
scp -O report.pdf user@203.0.113.10:~/

Large volumes or interrupted transfers

scp always copies everything anew. For large directories that you sync regularly, or for transfers that need to resume after an interruption, rsync over SSH is the more suitable tool.

Typical errors

  • Connection refused: The SSH service is not listening on this port. Check the port number and -P.
  • No such file or directory: The source path is incorrect. For a source on the server, a path without a leading slash is relative to the home directory.
  • Permission denied at destination: Your user is not allowed to write to the destination directory. Copy to your home directory and move the file afterwards with sudo.
  • Host key verification failed: The server key has changed, for example after a reinstallation. Remove the old entry with ssh-keygen -R 203.0.113.10 after verifying that it is your server.
These are the first three messages
ssh: connect to host 203.0.113.10 port 22: Connection refused
scp: stat local "report.pdf": No such file or directory
scp: dest open "/root/report.pdf": Permission denied

We tested all commands in this guide on 2 December 2026 โ€” with OpenSSH 9.6 on Ubuntu 24.04 LTS and OpenSSH 10.2 on Ubuntu 26.04 LTS. If a step changes at the manufacturer, we update it here along with the date.

Official documentation

Frequently asked questions about scp

Is scp secure?

Yes. scp runs over SSH; login and data are encrypted, and the same keys and permissions apply as with an SSH login.

Why is the port option -P for scp and -p for ssh?

For scp, the lowercase -p is already taken: it preserves timestamps and permissions from the source. Therefore, scp uses the uppercase P for the port.

When should I use rsync instead of scp?

rsync only transfers what has changed and can resume interrupted transfers. For single files, scp is sufficient; for large directories and regular synchronisation, rsync is better.

Is scp available on Windows?

Yes. Windows 10 and Windows 11 include the OpenSSH client; scp is available in PowerShell and the command prompt with the same options.

What does scp have to do with SFTP?

Since OpenSSH 9.0, scp uses the SFTP protocol internally, while commands and options remain the same. Use -O to switch back to the legacy protocol for older remote hosts.

Further reading

More tutorials

  • How to check your Ubuntu version, codename and kernel

    Linux basicsFor beginnersabout 2 min

    A single command in the terminal shows which Ubuntu version is running on a server. Here are the common ways with their output โ€” for the version with point release, the codename, the kernel and the architecture.

  • How to remove a directory in Linux with rm and rmdir

    Linux basicsFor beginnersabout 5 min

    In Linux, you delete an empty folder with rmdir and a folder including its contents with rm -r. This tutorial shows both commands with their messages, the variants with and without prompting, and what to check before running rm -rf โ€” because there is no recycle bin in the terminal.

  • How to update Ubuntu and upgrade to the next LTS release

    Linux basicsFor beginnersabout 15 min

    A server only stays secure if it receives its updates. This guide shows the three stages: applying updates manually, running security updates automatically and switching to the next LTS release.

A server for your files

Every VPS and Cloud Server is accessible via SSH โ€” scp works with it without any further setup.