scp (secure copy) is a command-line tool for copying files between machines over SSH.

It uses the same authentication and encryption as ssh, so no extra setup is needed beyond SSH access.

Basic Syntax

The general syntax of scp is:

scp [options] source destination

Either source or destination (or both) can be remote.

A remote path is written as:

user@host:/path/to/file

If user@ is omitted, the current local user is assumed.

Copy a local file to a remote machine

scp /path/to/local/file.txt user@remote_host:/path/to/remote/directory/

If the destination is a directory, the file is copied into it.

If the destination file name does not exist, it will be created.

If it exists, it is overwritten without warning.

Copy a file from a remote server to local

scp user@remote_host:/path/to/remote/file.txt /path/to/local/directory/

If the local target is a directory, the original file name is preserved.

Copy directories recursively

By default, scp only copies files. To copy directories, use the -r option:

scp -r results/ user@remote_host:/path/to/remote/directory/