scp

Copy a file or directory between your machine and a server, using the same login and keys as ssh.

scp <file> <user>@<host>:<path>
Save

Angle brackets are yours to fill in. Windows, Linux, macOS.

Examples for scp

  • Copy a file to a server

    scp <file> <user>@<host>:<path>
    Save

    The colon makes it remote. A path after the colon without a leading / starts in the user's home directory; with nothing after the colon, the file goes into home.

    scptool<file>path<user>@<host>:<path>the destination
  • Copy a file from a server

    scp <user>@<host>:<path> .
    Save

    Source first, destination second, as with cp. The . is the current directory here.

    scptool<user>@<host>:<path>the source .here
  • Copy a whole directory

    scp -r <directory> <user>@<host>:<path>
    Save

    Without -r, scp refuses to copy a directory. For large trees or repeated copies, rsync is faster, because it sends only what changed.

    scptool-rrecursive<directory>path<user>@<host>:<path>argument
  • Copy over a different SSH port

    scp -P <port> <file> <user>@<host>:<path>
    Save

    Uppercase -P, because lowercase -p already means keep the file times. ssh uses lowercase -p for the port.

    scptool-P <port>flag with value<file>path<user>@<host>:<path>argument
  • Copy with a specific key file

    scp -i <key-file> <file> <user>@<host>:<path>
    Save

    The same as ssh -i. The key file must be readable only by you: chmod 600.

    scptool-i <key-file>flag with value<file>path<user>@<host>:<path>argument

Flags

-r
Copy a directory and everything in it.
-P <port>
Connect to a port other than 22. Uppercase, unlike ssh.
-i <key-file>
Use this private key.
-C
Compress during the transfer. Helps on a slow link with text files.
-p
Keep the modification times and permissions.