Updated 28-Jun-2024
scp, the secure version of cp, aka copy, is pretty great, since it is straightforward to copy one or more files or directories from any one machine to any other machine (and the command could be running on a third machine).
SCP Syntax
Note: it is best to use sudo, and full paths for everything.
Second note: for using a private key at the destination, declare that first, and then the local or login+remote file(s).
scp
(-r
= recursive) (-i
private key) (user@server:directory/file
) or (/local/directory/file
) (-i
private key) (user@server:directory/file
) or (/local/directory/file
)
Note that the identity file needs to be in the ~/.ssh
directory or this will fail.
- scp
- optional -r for recursive directory structure
- optional -i for optional identity file aka private key
- Use the full path for the identity file (this file needs to be local to the machine on which scp is being run
- either a user@server: or a /local/directory/file for the source
- Note that there is no slash after the colon before the first directory name on a remote location
- either a user@server: or a /local/directory/file for the destination
Examples
- Use an identity file to upload a file to a server, with verbose feedback:
scp -v -i ~/.ssh/myprivatekey test.file [email protected]:/usr/local/bin
- Use an identity file to download recursively a directory to a workstation, with verbose feedback:
``