What Is the scp Command?

Category: FTP & File Management ยท Updated 2026-11-06

The scp command (secure copy) copies files between a local machine and a remote server, or between two remote servers, over an encrypted SSH connection on port 22. It reuses SSH authentication, including passwords or key pairs, and is built into Linux, macOS and modern Windows terminals. It is meant for quick one-off transfers rather than keeping large folders in sync, which is what rsync is for.

How scp works

scp connects to the SSH server (sshd) running on the remote machine, almost always on port 22, and authenticates the same way an interactive SSH session would, with a password or an SSH key pair. Once authenticated, it streams the file's bytes over that encrypted channel and writes them to the destination path. Because the whole transfer rides inside SSH, there is no separate unencrypted data connection to configure, unlike plain FTP.

scp always copies the entire file from start to finish. It does not compare the source and destination first, so re-running the same command re-sends the whole file even if only one byte changed.

Basic scp syntax and examples

The general pattern is scp [options] source destination, where either side can be local or remote in the form user@host:/path.

# Upload a local file to a remote server
scp index.html user@example.com:/home/user/public_html/

# Download a file from a remote server
scp user@example.com:/home/user/backup.sql ./backup.sql

# Copy a whole folder recursively
scp -r ./site user@example.com:/home/user/public_html/

# Use a non-default SSH port (22222 here)
scp -P 22222 file.txt user@example.com:/home/user/

# Copy directly between two remote servers
scp userA@serverA.com:/data/file.tar.gz userB@serverB.com:/data/

Note the capital -P for the port in scp, which differs from the lowercase -p used by the ssh and sftp commands.

scp vs. rsync vs. sftp

scprsyncsftp
TransportSSHSSH (usually)SSH
Resumes interrupted transfersNoYesPartial, client-dependent
Transfers only changed dataNo, copies whole fileYes, delta transferNo
Interactive session (browse, delete)NoNoYes
Best forA single quick copyKeeping large folders in syncBrowsing and managing remote files

For a one-time grab of a single file, scp is the simplest option. For repeated backups of a large directory, rsync is faster because it skips files that have not changed.

Common scp errors

  • Permission denied: the remote account cannot write to that path, or the SSH login itself failed; check the username and key.
  • No such file or directory: the destination folder does not exist yet, since scp will not create parent directories for you.
  • Host key verification failed: the server's SSH fingerprint changed, often after a server migration; remove the old entry from ~/.ssh/known_hosts once you have confirmed the new host is legitimate.
  • Connection refused: SSH is not running, is on a different port, or is blocked by a firewall.

Frequently asked questions

What does scp stand for?

scp stands for secure copy. It is both the name of the command and an informal name for the file transfer it performs over SSH.

How do I copy a file to a remote server using scp?

Run scp followed by the local file path and the destination in the form user@host:/path, for example scp file.txt user@example.com:/home/user/. You will be prompted for a password unless SSH key authentication is set up.

How do I copy an entire folder with scp?

Add the -r flag before the source path, for example scp -r ./myfolder user@example.com:/home/user/. Without -r, scp will refuse to copy a directory.

Is scp faster than rsync?

For a single small file the speeds are similar. For repeated transfers of large folders, rsync is usually faster overall because it only sends the parts that changed instead of the whole file.

Why do I get "Permission denied" with scp?

This usually means the SSH login itself was rejected, or the account does not have write access to the destination folder. Check the username, password or key, and confirm the remote path is writable.

Does scp work on Windows?

Yes. Modern Windows includes an OpenSSH client with scp built into PowerShell and Command Prompt, and tools like WinSCP offer scp and sftp through a graphical interface.

What port does scp use?

scp uses the same port as SSH, which is port 22 by default. If a server runs SSH on a custom port, pass it with the capital -P flag, for example scp -P 2222.

Related topics