SCP command with examples
84 views

SCP, or Secure Copy Protocol, is a command-line utility that facilitates secure file transfers between local and remote servers. Built on top of the SSH (Secure Shell) protocol, SCP encrypts the data during transit, ensuring a secure and private exchange.

Basic SCP Syntax:

bash

scp [options] [source] [destination]

Common Options:

-r: Recursively copy entire directories. -P: Specify a custom SSH port (default is 22). -i: Provide the path to the identity file (private key) for authentication.

Examples:

Copy a File to a Remote Server: bash

scp localfile.txt username@remote-server:/path/to/destination/

This command copies localfile.txt from the local machine to the specified path on the remote server.

Copy a File from a Remote Server:

bash

scp username@remote-server:/path/to/file.txt /local/destination/

Here, file.txt from the remote server is copied to the local destination.

Copy an Entire Folder to a Remote Server:

bash

scp -r localfolder username@remote-server:/path/to/destination/

The -r flag recursively copies the entire localfolder to the specified path on the remote server.

Copy an Entire Folder from a Remote Server:

bash

scp -r username@remote-server:/path/to/folder /local/destination/ This command retrieves the contents of the remote folder and copies it recursively to the local destination.

Why Choose SCP:

Security Assurance:    SCP uses SSH for authentication and data encryption, ensuring secure transfers. Efficiency in Transfers:    SCP efficiently handles the transfer of files and directories with minimal overhead. Cross-Server Connectivity:    SCP enables seamless communication between servers, making cross-server file transfers straightforward.

Whether you're a system administrator managing servers or a developer ensuring secure file exchanges, mastering SCP is a valuable skill in your toolkit. It combines security with efficiency, making it an essential command for secure file transfers in the Linux environment.

Top