How to Use SCP
Introduction
The SCP (Secure Copy Protocol) command is used to securely transfer files between a local and remote host, or between two remote hosts. It is built on top of the SSH (Secure Shell) protocol, ensuring secure file transfers over the network.
Prerequisites
Before using SCP, make sure you have the following:
1. Local machine with SCP installed.
2. Access to the remote machine’s SSH service.
3. Appropriate credentials (username/password or SSH key) for authentication.
Syntax
The basic syntax for using SCP is as follows:
bash
scp [OPTIONS] SOURCE DESTINATION
Usage Examples
-
Copy a file from a local machine to a remote machine:
bash
scp /path/to/local/file username@remote:/path/on/remote -
Copy a file from a remote machine to the local machine:
bash
scp username@remote:/path/to/remote/file /path/on/local -
Copy an entire directory from a local machine to a remote machine:
bash
scp -r /path/to/local/directory username@remote:/path/on/remote -
Copy an entire directory from a remote machine to the local machine:
bash
scp -r username@remote:/path/to/remote/directory /path/on/local
Options
Here are some common options that can be used with SCP:
– -r
: Recursively copy entire directories.
– -P PORT
: Specify a custom SSH port (default is 22).
– -i IDENTITY_FILE
: Use a specific identity file for SSH authentication.
– -v
: Verbose output, showing detailed progress during file transfer.
– -C
: Enable compression during file transfer.
Conclusion
SCP provides a secure and efficient way to transfer files between local and remote machines. By following the syntax and examples mentioned above, you can easily utilize SCP for your file transfer needs.