What is scp? Secure file copying over SSH

Author: Published

In brief: In computing, SCP (Secure Copy Protocol) is a way to copy files securely between computers, while scp is the command used to transfer them over SSH, an encrypted connection to a remote system. You can use it to upload a file to a server or download a backup to your own computer. Modern versions of scp in OpenSSH use SFTP by default rather than the older SCP protocol. The acronym also appears in the name of the fictional universe SCP Foundation—a separate meaning unrelated to data transfer.

What is scp used for, and how does it work?

The scp command copies data from a specified source to a destination. Typical uses include uploading a website archive to a server, downloading logs for analysis, or copying a configuration file. You run it in a terminal, supplying paths and the details needed to access the remote computer.

SSH encrypts the connection and enables authentication: verifying the identities of the parties involved in the connection. Users usually log in with a password or an SSH key. An SSH key consists of two related parts: the public key is placed on the server, while the private key stays on your computer and must be kept secret.

However, encrypting the transfer does not mean that the file remains encrypted once it is saved to disk. scp is not a complete backup system either: on its own, it provides no version history, archive rotation, or tests to verify that data can be restored.

What do you need before copying files?

You need an scp client on the computer from which you initiate the transfer. It is available on many Linux and macOS installations, and on Windows you can use the OpenSSH client. Check whether OpenSSH is installed with ssh -V. To check whether scp itself is available, run scp without arguments; the program should display usage information.

The server must have SSH running and, for the default mode in modern OpenSSH, support SFTP as well. You need the server address, a username, a way to log in, and permission to access the relevant directory. An account that only supports FTP is not enough.

Before your first transfer, you can test whether you can log in:

The address 192.0.2.10 is an example—replace it with your server’s address. On the first connection, the client may ask you to approve the host key fingerprint, which identifies the server’s key. Compare it with information from the administrator or a trusted provider control panel rather than accepting it automatically.

How to use scp: three practical examples

The basic command structure is:

scp [options] source destination

A remote location is usually written as user@server:path. The colon separates the server address from the file or directory path.

Uploading a file to a server: suppose you have an archive called website.tar.gz in the current directory and want to put it in Anna’s home directory:

scp strona.tar.gz [email protected]:/home/anna/

Downloading a file from a server: reverse the order of the source and destination. The dot at the end means the current directory on the computer where you run the command:

scp [email protected]:/home/anna/backup.zip .

Uploading an entire directory: add the -r option to enable recursive copying, which includes the directory’s contents and its subdirectories:

scp -r ./photos [email protected]:/home/anna/

If SSH runs on a port other than the default, 22, specify it with uppercase -P, for example scp -P 2222 file.txt [email protected]:/home/anna/. Lowercase -p has a different meaning: it preserves access and modification times, as well as the file’s permission bits. Put local paths containing spaces in quotation marks, for example "annual report.pdf".

When should you choose scp, SFTP, or rsync?

The names SCP and SFTP are sometimes confused because both use SSH. Historically, they were different file transfer protocols. Since OpenSSH 9.0, the scp command transfers files using SFTP by default, while retaining its familiar syntax.

In practice, choose the tool to suit the task:

The -O option in OpenSSH forces the use of the old SCP protocol. Treat it as a solution to a specific compatibility problem, not as a default setting. Check the options and behavior supported by your version in the local documentation, man scp, or the official OpenSSH documentation.

Common errors and a safe first transfer

The message Permission denied may indicate a login failure or insufficient permissions for a file or directory. If logging in through ssh works, check whether the remote user can write to the destination. No such file or directory usually indicates an incorrect path, while Connection refused may mean that the port is wrong or the SSH service is not running.

scp can overwrite an existing file without asking. Before uploading data, check the order of the arguments and the contents of the destination directory. Remember that a relative remote path is usually resolved from the user’s home directory, not from the directory open on your own computer.

For your first test, transfer a small, unimportant file to a separate directory. Once the transfer finishes, check that the file is there and verify its contents. Only then use the same command pattern for your actual data.

See also: What is AGI?

Read also

Learn how PHP-FPM handles PHP requests, how it differs from a web server, and how to tune processes for traffic and hosting resources.
Learn how BIND, open-source DNS server software, handles domains, how its two roles differ and when running it yourself makes sense.
Learn what Poland’s REGON register and identification number mean, how they differ from NIP and KRS, and how to check a business’s details.