SCP (Secure Copy Protocol) is a command-line utility for securely copying files between local and remote hosts. This cheat sheet provides essential SCP commands for efficient file transfers.
Introduction:
SCP, based on the SSH protocol, allows secure and encrypted file transfers between hosts. It is a simple and secure way to copy files and directories over a network.
Copying Files to a Remote Server:
| Command | Description |
|---|---|
scp [file] [username]@[hostname]:[destination] | Copy a file to a remote server. |
scp -P [port] [file] [username]@[hostname]:[destination] | Specify a custom SSH port for connection. |
Copying Directories to a Remote Server:
| Command | Description |
|---|---|
scp -r [directory] [username]@[hostname]:[destination] | Copy a directory and its contents recursively. |
Copying Files from a Remote Server:
| Command | Description |
|---|---|
scp [username]@[hostname]:[remote_file] [destination] | Copy a file from a remote server to the local machine. |
Preserving File Attributes:
| Command | Description |
|---|---|
scp -p [file] [username]@[hostname]:[destination] | Preserve the original file attributes (permissions, timestamps). |
scp -rp [directory] [username]@[hostname]:[destination] | Preserve file attributes for directories. |
Using SCP with Key-Based Authentication:
| Command | Description |
|---|---|
scp -i [private_key] [file] [username]@[hostname]:[destination] | Specify a private key for authentication. |
Displaying Progress Information:
| Command | Description |
|---|---|
scp -v [file] [username]@[hostname]:[destination] | Verbose mode, display detailed information during transfer. |
Miscellaneous:
| Command | Description |
|---|---|
scp -C [file] [username]@[hostname]:[destination] | Compress the data during transfer. |
scp --help | Display SCP command-line options and usage. |
Conclusion
SCP is a straightforward and secure way to copy files between local and remote hosts. This cheat sheet offers a quick reference for common SCP commands, covering file and directory transfers, preserving attributes, and using key-based authentication. Whether you are a system administrator or a developer, mastering these commands will enhance your efficiency in securely transferring files between systems.