---
title: "Copy files over SSH with scp, sftp and rsync · CloudSat"
description: "When to use scp, sftp or rsync to move files to and from a server over SSH, with working commands for ports, keys, resumes, jump hosts and Windows."
url: https://cloudsat.io/learn/transfer-files-over-ssh-scp-sftp-rsync
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Linux](https://cloudsat.io/learn/topic/linux)

# Copy files over SSH with scp, sftp and rsync

When to use scp, sftp or rsync to move files to and from a server over SSH, with working commands for ports, keys, resumes, jump hosts and Windows.

CloudSat team November 18, 2026 7 min read

`scp`, `sftp` and `rsync` all travel inside an SSH connection, so they share the same login, keys, port and encryption. If `ssh user@server` works, all three work. They differ in what they are good at: `scp` makes a quick one-off copy, `sftp` opens an interactive session that can resume, and `rsync` sends only what changed, which makes it the tool for large trees and repeated transfers. The examples use `deploy@203.0.113.10`; replace both parts with your own user and server.

## Which tool for which job

| Job | Use | Why |
| --- | --- | --- |
| Copy one file or folder, once | `scp` | shortest command, nothing to set up |
| Browse remote folders and pick files | `sftp` | `ls` and `cd` on both sides |
| Resume a large interrupted transfer | `rsync -P` or `sftp` with `reget` | continues where it stopped |
| Mirror a directory every day | `rsync` | sends only the changed parts |
| Move thousands of small files | `tar` piped through `ssh` | one stream instead of per-file overhead |
| Give someone upload access, no shell | an SFTP-only account | locked into one directory |

## scp for quick copies

```bash
scp ./site.tar.gz deploy@203.0.113.10:/srv/backups/   # upload
scp deploy@203.0.113.10:/var/log/nginx/access.log .    # download to here
scp -r ./public deploy@203.0.113.10:/srv/site/         # whole directory
scp -P 2222 -i ~/.ssh/id_ed25519 db.sql deploy@203.0.113.10:/tmp/
```

The remote side is always `user@host:path`, and a path without a leading slash is relative to the remote user's home directory. The port option is a capital `-P`, while `ssh` uses a lowercase `-p`; mixing them up is the most common scp mistake. In scp, lowercase `-p` preserves modification times and modes. `-l 8000` caps bandwidth at 8,000 Kbit/s, and `-3` copies between two remote hosts through your machine.

### What changed in OpenSSH 9.0

Since OpenSSH 9.0 (April 2022), `scp` uses the SFTP protocol under the hood instead of the legacy SCP/RCP protocol, which handed file names to the remote shell and was hard to make safe. For daily use nothing changes. Two edge cases do: remote wildcards are expanded by the server's SFTP code instead of a shell, and servers with no SFTP subsystem refuse the copy. For those, `scp -O` forces the legacy protocol.

## sftp for an interactive session

```bash
sftp -P 2222 deploy@203.0.113.10
```

At the `sftp>` prompt you get a small set of file commands. Those starting with `l` act on your local machine:

```text
ls                 list the remote directory
lls                list the local directory
cd /srv/backups    change the remote directory
lcd ~/Downloads    change the local directory
get -r logs        download a directory
put report.pdf     upload a file
reget big.iso      resume an interrupted download
bye                close the session
```

`sftp -b batch.txt deploy@203.0.113.10` runs a list of commands without interaction, which suits cron jobs against servers that allow SFTP but no shell. Batch mode cannot ask for a password, so it needs key authentication. Graphical clients such as FileZilla, WinSCP and Cyberduck speak the same protocol, so anything you can do at the prompt you can also do with drag and drop.

### SFTP-only accounts

For a person who should upload files and nothing else, OpenSSH can lock an account into one directory with no shell. Create the user and the directories first:

```bash
sudo groupadd sftponly
sudo useradd -G sftponly -s /usr/sbin/nologin alice
sudo passwd alice
sudo mkdir -p /srv/sftp/alice/upload
sudo chown root:root /srv/sftp/alice && sudo chmod 755 /srv/sftp/alice
sudo chown alice:alice /srv/sftp/alice/upload
```

Then add this block at the end of `/etc/ssh/sshd_config`, since a `Match` section lasts until the next `Match` line:

```text
Match Group sftponly
    ChrootDirectory /srv/sftp/%u
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no
```

The chroot directory must belong to root and must not be writable by the user, which is why uploads go into the `upload` subdirectory. Check the syntax with `sudo sshd -t`, then reload the service (`ssh` on Debian and Ubuntu, `sshd` on the RHEL family).

## rsync for big and repeated transfers

```bash
rsync -avP ./site/ deploy@203.0.113.10:/srv/site/
rsync -avP --dry-run --delete ./site/ deploy@203.0.113.10:/srv/site/
rsync -avP -e "ssh -p 2222 -i ~/.ssh/id_ed25519" ./site/ deploy@203.0.113.10:/srv/site/
rsync -avP --exclude 'node_modules/' --exclude '.git/' ./app/ deploy@203.0.113.10:/srv/app/
```

`-a` (archive) recurses and keeps permissions, timestamps and symlinks. `-v` lists files, and `-P` combines `--partial` (keep half-sent files so the next run resumes them) with `--progress`. The trailing slash on the source decides the shape of the result: `./site/` copies the contents of `site` into the target, while `./site` creates a `site` folder inside it.

`--delete` removes files on the destination that no longer exist on the source. That is what makes a true mirror, and also how a wrong path wipes a directory, so run the same command with `--dry-run` first and read the list. Add `-z` for compression only on slow links with compressible data; with images, archives or video it burns CPU and saves nothing.

rsync has to be installed on both machines, and `rsync: command not found` coming from the remote side means it is missing there. Keep it updated: rsync 3.4.0, released in January 2025, fixed six vulnerabilities, the worst of them in the rsync daemon. Running rsync over SSH, as in every example here, avoids exposing an `rsync://` daemon to the internet at all.

## Speed and reliability tips

For thousands of small files, per-file overhead dominates. Stream one tar archive through a single connection instead:

```bash
tar czf - ./photos | ssh deploy@203.0.113.10 'tar xzf - -C /srv/'
```

Start long transfers inside `tmux` on the machine that runs the command, so a sleeping laptop or a dropped session does not kill the copy. To reach a server that sits behind a bastion host, add `-J`: `scp -J bastion.example.com file.txt deploy@10.0.0.5:/tmp/`, or for rsync `-e "ssh -J bastion.example.com"`.

Typing ports and key paths gets old. Describe the server once in `~/.ssh/config` and every tool picks it up:

```text
Host web1
    HostName 203.0.113.10
    User deploy
    Port 2222
    IdentityFile ~/.ssh/id_ed25519
```

After that, `scp backup.tar.gz web1:/srv/backups/`, `sftp web1` and `rsync -avP ./site/ web1:/srv/site/` all work. For files that matter, compare `sha256sum` output on both ends; rsync already verifies each file it transfers with a checksum.

## From Windows

Windows 10 and 11 include the OpenSSH client, so `ssh`, `scp` and `sftp` work in PowerShell with the same syntax:

```powershell
scp .\report.pdf deploy@203.0.113.10:/tmp/
scp -r deploy@203.0.113.10:/srv/backups C:\Users\me\Downloads\
```

There is no native rsync on Windows. Run it inside WSL, or use a graphical SFTP client such as WinSCP or FileZilla. The CloudSat docs walk through [connecting over SSH from Windows](https://cloudsat.io/docs/ssh-from-windows), keys included.

## When a transfer fails

- `Permission denied (publickey)`: wrong user or wrong key. `ssh -v deploy@203.0.113.10` shows which keys your client offers.
- `subsystem request failed` followed by `Connection closed`: the server has no SFTP subsystem. Enable the `Subsystem sftp` line in `sshd_config`, or use `scp -O`.
- `REMOTE HOST IDENTIFICATION HAS CHANGED`: the server's host key no longer matches the one you saved. After a rebuild that is expected, and `ssh-keygen -R 203.0.113.10` clears the old entry. If you did not rebuild anything, stop and find out why before you connect.
- Slow copies: check whether one side's CPU is saturated by encryption, whether you are compressing data that does not compress, and whether a disk, not the network, is the bottleneck.

## FAQ

### Is scp deprecated?

The legacy SCP protocol is; the `scp` command is not. Modern OpenSSH runs scp over SFTP, so it remains fine for simple copies. Reach for rsync or sftp whenever you might need to resume.

### Can I resume an interrupted scp?

No, scp starts again from zero. Use `rsync -P`, which keeps the partial file and continues, or `reget` and `reput` inside sftp.

### Which tool is fastest?

For one large file the three perform similarly, since encryption and the network set the pace. rsync wins on every run after the first, because unchanged files are skipped. A tar stream wins when you move thousands of small files.

### How do I stop typing a password every time?

Use SSH keys: create one with `ssh-keygen -t ed25519` and install it with `ssh-copy-id deploy@203.0.113.10`. On CloudSat you can attach your public key when you deploy a server ([add and use SSH keys](https://cloudsat.io/docs/manage-ssh-keys)), so key login works from the first boot.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Linux](https://cloudsat.io/learn/topic/linux)

- [Linux commands you need on a new server](https://cloudsat.io/learn/essential-linux-commands-for-servers): Linux Linux commands you need on a new server 8 min read
- [Find what is filling your Linux disk with df, du and ncdu](https://cloudsat.io/learn/find-what-is-filling-your-linux-disk): Linux Find what is filling your Linux disk with df, du and ncdu 7 min read
- [Bash functions with arguments, return values and scope](https://cloudsat.io/learn/bash-functions-arguments-return-scope): Linux Bash functions with arguments, return values and scope 8 min read
- [rsync backups over SSH: versioned snapshots with --link-dest](https://cloudsat.io/learn/versioned-backups-with-rsync-over-ssh): Linux rsync backups over SSH: versioned snapshots with --link-dest 6 min read
