Linux SCP Command Guide
Introduction
SCP (Secure Copy Protocol) is a command-line utility used to securely transfer files between hosts on a network. It uses SSH for data transfer and provides the same authentication and security as SSH.
Usage
To copy files, use the following command:
scp [options] [source] [destination]
Common Options
-r
: Recursively copy entire directories.-P <port>
: Specify the port to connect to.-i <identity_file>
: Use a specific private key for authentication.
Examples
-
Copy a file to a remote server:
scp localfile.txt [email protected]:/path/to/destination/
-
Copy a file from a remote server:
scp [email protected]:/path/to/remotefile.txt /local/destination/
-
Recursively copy a directory to a remote server:
scp -r localdir/ [email protected]:/path/to/destination/
-
Specify a port for the connection:
scp -P 2222 localfile.txt [email protected]:/path/to/destination/