scp Cheat Sheet

Here’s a cheat sheet for using scp (secure copy) to transfer files between local and remote systems in Unix-like environments:

Copy from Local to Remote

scp local_file username@remote_host:remote_directory

Example:

scp myfile.txt user@remote-server:/path/to/destination/

Copy from Remote to Local

scp username@remote_host:remote_file local_directory

Example:

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

Copy with Port Specification

scp -P port_number local_file username@remote_host:remote_directory

Example:

scp -P 2222 myfile.txt user@remote-server:/path/to/destination/

Copying Entire Directories

scp -r local_directory username@remote_host:remote_directory

Example:

scp -r myfolder user@remote-server:/path/to/destination/

Copying with Compression

scp -C local_file username@remote_host:remote_directory

Preserving File Attributes

scp -p local_file username@remote_host:remote_directory

Verbose Mode (Show Details)

scp -v local_file username@remote_host:remote_directory

Using Key for Authentication

scp -i path/to/private_key local_file username@remote_host:remote_directory

Example:

scp -i ~/.ssh/id_rsa myfile.txt user@remote-server:/path/to/destination/

Using Specific Cipher

scp -c cipher local_file username@remote_host:remote_directory

Example:

scp -c aes256 myfile.txt user@remote-server:/path/to/destination/

Quiet Mode (Suppress Output)

scp -q local_file username@remote_host:remote_directory

Secure Copy Between Two Remote Hosts

scp user1@remote1:/path/to/file user2@remote2:/path/to/destination/

This cheat sheet covers some commonly used scp commands and options. Adjust the parameters based on your specific requirements.