Post

Mastering scp: A Comprehensive Guide to Secure Copy Protocol in Linux

The ability to securely transfer files between systems is paramount. Whether you’re a system administrator, a developer, or an everyday Linux user, the need to move files and directories across networks and between machines is a common task. This is where the scp (Secure Copy Protocol) command comes into play. scp is a powerful and versatile command-line utility that allows users to securely copy files and directories between local and remote systems using the SSH (Secure Shell) protocol. By leveraging the encryption capabilities of SSH, scp ensures that your data remains confidential and secure during transit, making it an ideal choice for transferring sensitive information over untrusted networks.

some common options for the scp (Secure Copy Protocol) command in Linux along with descriptions for each option:

OptionDescription
-P <port>Specifies the port number to connect to on the remote host. Default is 22.
-pPreserves modification times, access times, and modes from the original file.
-rRecursively copies directories and their contents.
-vVerbose mode; displays debugging messages during transfer.
-qQuiet mode; suppresses the progress meter and non-error messages.
-CEnables compression during transfer.
-i <identity_file>Specifies the identity file (private key) for public key authentication.
-l <limit>Limits the bandwidth, specified in Kbit/s.
-BSelects batch mode for automated transfers.
-o <ssh_option>Passes additional options to SSH for configuring the connection (e.g., -o "ProxyJump=user@proxy").
-F <configfile>Specifies an alternative SSH configuration file.
-4Forces scp to use IPv4 addresses only.
-6Forces scp to use IPv6 addresses only.
-TDisables strict filename checking, allowing the remote end to overwrite existing files.
-S <program>Specifies the program to use for the encrypted connection (default is ssh).

Common Options:

scp -P <port>

The scp (secure copy) command is used to securely transfer files between a local host and a remote host or between two remote hosts over an SSH (Secure Shell) connection. The -P option in scp is used to specify the port number for the SSH connection.

Here are some advanced examples demonstrating the usage of scp with the -P option:

Example 1: Copy a File from Local Host to Remote Host on a Specific Port

Copy a file named example.txt from the local host to a remote host (remote_host) on port 2222:

1
scp -P 2222 example.txt user@remote_host:/path/to/destination/

In this example:

  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a File from Remote Host to Local Host on a Specific Port

Copy a file named example.txt from a remote host (remote_host) to the local host on port 2222:

1
scp -P 2222 user@remote_host:/path/to/example.txt /local/destination/

In this example:

  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • user@remote_host:/path/to/example.txt: Specifies the username, remote host, and path to the file on the remote host.
  • /local/destination/: Specifies the destination directory on the local host.

Example 3: Copy a Directory from Local Host to Remote Host on a Specific Port

Copy a directory named data from the local host to a remote host (remote_host) on port 2222:

1
scp -P 2222 -r data/ user@remote_host:/path/to/destination/

In this example:

  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • -r: Recursively copy the directory and its contents.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy a File from Remote Host to Another Remote Host on a Specific Port

Copy a file named example.txt from one remote host (remote_host1) to another remote host (remote_host2) on port 2222:

1
scp -P 2222 user1@remote_host1:/path/to/example.txt user2@remote_host2:/path/to/destination/

In this example:

  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • user1@remote_host1:/path/to/example.txt: Specifies the username, remote host, and path to the file on the first remote host.
  • user2@remote_host2:/path/to/destination/: Specifies the username, second remote host, and destination path on the second remote host.

Example 5: Copy Multiple Files from Remote Host to Local Host on a Specific Port

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host on port 2222:

1
scp -P 2222 user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

These examples demonstrate how to use the scp command with the -P option to specify a custom port number for the SSH connection. The -P option allows you to establish an SSH connection over a non-default port, providing flexibility when transferring files between hosts over a secure connection.

scp -p

The -p option in the scp (secure copy) command preserves the file attributes such as timestamps, access permissions, and ownership during the file transfer. When you use the -p option with scp, the file attributes of the original file are retained on the copied file.

Here are some advanced examples demonstrating the usage of scp with the -p option:

Example 1: Copy a File with Preserved Attributes from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) while preserving the file attributes:

1
scp -p example.txt user@remote_host:/path/to/destination/

In this example:

  • -p: Preserves the file attributes (timestamps, access permissions, ownership).
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory with Preserved Attributes from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) while preserving the file attributes:

1
scp -rp data/ user@remote_host:/path/to/destination/

In this example:

  • -p: Preserves the file attributes (timestamps, access permissions, ownership).
  • -r: Recursively copy the directory and its contents.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File with Preserved Attributes from Remote Host to Local Host

Copy a file named example.txt from a remote host (remote_host) to the local host while preserving the file attributes:

1
scp -p user@remote_host:/path/to/example.txt /local/destination/

In this example:

  • -p: Preserves the file attributes (timestamps, access permissions, ownership).
  • user@remote_host:/path/to/example.txt: Specifies the username, remote host, and path to the file on the remote host.
  • /local/destination/: Specifies the destination directory on the local host.

Example 4: Copy a Directory with Preserved Attributes from Remote Host to Local Host

Copy a directory named data from a remote host (remote_host) to the local host while preserving the file attributes:

1
scp -rp user@remote_host:/path/to/data/ /local/destination/

In this example:

  • -p: Preserves the file attributes (timestamps, access permissions, ownership).
  • -r: Recursively copy the directory and its contents.
  • user@remote_host:/path/to/data/: Specifies the username, remote host, and path to the directory on the remote host.
  • /local/destination/: Specifies the destination directory on the local host.

Example 5: Copy Multiple Files with Preserved Attributes from Remote Host to Local Host

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host while preserving the file attributes:

1
scp -p user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -p: Preserves the file attributes (timestamps, access permissions, ownership).
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

These examples demonstrate how to use the scp command with the -p option to preserve the file attributes such as timestamps, access permissions, and ownership during the file transfer. The -p option ensures that the copied files and directories retain their original attributes, maintaining data integrity and consistency between the source and destination locations.

scp -r

The -r option in the scp (secure copy) command allows you to recursively copy directories and their contents between hosts. When you use the -r option with scp, it will copy the specified directory and all of its subdirectories and files to the destination.

Here are some advanced examples demonstrating the usage of scp with the -r option:

Example 1: Recursively Copy a Directory from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host):

1
scp -r data/ user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory data and its contents.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Recursively Copy a Directory from Remote Host to Local Host

Copy a directory named data from a remote host (remote_host) to the local host:

1
scp -r user@remote_host:/path/to/data/ /local/destination/

In this example:

  • -r: Recursively copy the directory data and its contents.
  • user@remote_host:/path/to/data/: Specifies the username, remote host, and path to the directory on the remote host.
  • /local/destination/: Specifies the destination directory on the local host.

Example 3: Recursively Copy Multiple Directories from Remote Host to Local Host

Copy multiple directories (dir1, dir2) from a remote host (remote_host) to the local host:

1
scp -r user@remote_host:"/path/to/dir1 /path/to/dir2" /local/destination/

In this example:

  • -r: Recursively copy the directories dir1 and dir2 and their contents.
  • user@remote_host:"/path/to/dir1 /path/to/dir2": Specifies the username, remote host, and paths to the directories on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

Example 4: Recursively Copy a Directory with Preserved Attributes from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) while preserving the file attributes:

1
scp -rp data/ user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory data and its contents.
  • -p: Preserves the file attributes (timestamps, access permissions, ownership).
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 5: Recursively Copy a Directory Excluding Certain Files from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host), excluding certain files (e.g., file1.txt, file2.txt):

1
scp -r --exclude={file1.txt,file2.txt} data/ user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory data and its contents.
  • --exclude={file1.txt,file2.txt}: Excludes the specified files (file1.txt, file2.txt) from the copy operation.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -r option to recursively copy directories and their contents between hosts. The -r option is useful when transferring directories containing multiple files and subdirectories, allowing you to maintain the directory structure and contents across the source and destination locations.

scp -v

The -v option in the scp (secure copy) command stands for “verbose.” When you use the -v option with scp, it displays detailed information about the progress of the file transfer, including the authentication process, file transfers, and any errors or warnings encountered during the operation.

Here are some advanced examples demonstrating the usage of scp with the -v option:

Example 1: Copy a File with Verbose Output from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with verbose output:

1
scp -v example.txt user@remote_host:/path/to/destination/

In this example:

  • -v: Enables verbose output to display detailed information about the file transfer process.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory with Verbose Output from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) with verbose output:

1
scp -vr data/ user@remote_host:/path/to/destination/

In this example:

  • -v: Enables verbose output to display detailed information about the file transfer process.
  • -r: Recursively copy the directory data and its contents.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File with Verbose Output and Compression from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with verbose output and compression:

1
scp -vC example.txt user@remote_host:/path/to/destination/

In this example:

  • -v: Enables verbose output to display detailed information about the file transfer process.
  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy a File with Verbose Output and Specified Port from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) on port 2222 with verbose output:

1
scp -v -P 2222 example.txt user@remote_host:/path/to/destination/

In this example:

  • -v: Enables verbose output to display detailed information about the file transfer process.
  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 5: Copy Multiple Files with Verbose Output from Remote Host to Local Host

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host with verbose output:

1
scp -v user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -v: Enables verbose output to display detailed information about the file transfer process.
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

These examples demonstrate how to use the scp command with the -v option to enable verbose output, providing detailed information about the file transfer process. The -v option is useful for troubleshooting file transfer issues, monitoring progress, and gaining insights into the authentication process and data transfer operations between the source and destination hosts.

scp -q

The -q option in the scp (secure copy) command stands for “quiet.” When you use the -q option with scp, it suppresses the non-error messages and only displays the necessary output, making the file transfer process more silent.

Here are some advanced examples demonstrating the usage of scp with the -q option:

Example 1: Copy a File Quietly from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) quietly:

1
scp -q example.txt user@remote_host:/path/to/destination/

In this example:

  • -q: Enables quiet mode to suppress non-error messages during the file transfer.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory Quietly from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) quietly:

1
scp -qr data/ user@remote_host:/path/to/destination/

In this example:

  • -q: Enables quiet mode to suppress non-error messages during the file transfer.
  • -r: Recursively copy the directory data and its contents.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File Quietly with Specified Port from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) on port 2222 quietly:

1
scp -q -P 2222 example.txt user@remote_host:/path/to/destination/

In this example:

  • -q: Enables quiet mode to suppress non-error messages during the file transfer.
  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy Multiple Files Quietly from Remote Host to Local Host

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host quietly:

1
scp -q user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -q: Enables quiet mode to suppress non-error messages during the file transfer.
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

Example 5: Copy a File Quietly with Compression from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with quiet output and compression:

1
scp -qC example.txt user@remote_host:/path/to/destination/

In this example:

  • -q: Enables quiet mode to suppress non-error messages during the file transfer.
  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -q option to enable quiet mode, suppressing non-error messages during the file transfer process. The -q option is useful for minimizing the output and creating a more silent file transfer experience, especially when dealing with large files or batch operations where less verbose output is desired.

scp -C

The -C option in the scp (secure copy) command enables compression during the file transfer. When you use the -C option with scp, the data being transferred is compressed before sending, which can help reduce the amount of data sent over the network and speed up the file transfer process, especially for large files or slow network connections.

Here are some advanced examples demonstrating the usage of scp with the -C option:

Example 1: Copy a File with Compression from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with compression:

1
scp -C example.txt user@remote_host:/path/to/destination/

In this example:

  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory with Compression from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) with compression:

1
scp -rC data/ user@remote_host:/path/to/destination/

In this example:

  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • -r: Recursively copy the directory data and its contents.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File with Compression and Verbose Output from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with compression and verbose output:

1
scp -vC example.txt user@remote_host:/path/to/destination/

In this example:

  • -v: Enables verbose output to display detailed information about the file transfer process.
  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy Multiple Files with Compression from Remote Host to Local Host

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host with compression:

1
scp -C user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

Example 5: Copy a Large File with Compression from Local Host to Remote Host

Copy a large file named large_file.bin (e.g., 1GB) from the local host to a remote host (remote_host) with compression:

1
scp -C large_file.bin user@remote_host:/path/to/destination/

In this example:

  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • large_file.bin: Specifies the large file (e.g., 1GB) to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -C option to enable compression during the file transfer process. The -C option can be particularly beneficial when transferring large files or when using slow network connections, as it helps reduce the amount of data sent over the network, leading to faster and more efficient file transfers.

scp -i <identity_file>

The -i <identity_file> option in the scp (secure copy) command allows you to specify an identity (private key) file for public key authentication during the SSH connection. This option is useful when you have multiple SSH key pairs and want to use a specific private key for authentication, rather than the default private key (~/.ssh/id_rsa).

Here are some advanced examples demonstrating the usage of scp with the -i <identity_file> option:

Example 1: Copy a File Using Specific Private Key from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using a specific private key (private_key.pem):

1
scp -i private_key.pem example.txt user@remote_host:/path/to/destination/

In this example:

  • -i private_key.pem: Specifies the specific private key (private_key.pem) for public key authentication.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory Using Specific Private Key from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) using a specific private key (private_key.pem):

1
scp -r -i private_key.pem data/ user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory data and its contents.
  • -i private_key.pem: Specifies the specific private key (private_key.pem) for public key authentication.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File Using Specific Private Key and Port from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) on port 2222 using a specific private key (private_key.pem):

1
scp -i private_key.pem -P 2222 example.txt user@remote_host:/path/to/destination/

In this example:

  • -i private_key.pem: Specifies the specific private key (private_key.pem) for public key authentication.
  • -P 2222: Specifies the port number 2222 for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy Multiple Files Using Specific Private Key from Remote Host to Local Host

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host using a specific private key (private_key.pem):

1
scp -i private_key.pem user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -i private_key.pem: Specifies the specific private key (private_key.pem) for public key authentication.
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

Example 5: Copy a Large File Using Specific Private Key from Local Host to Remote Host

Copy a large file named large_file.bin (e.g., 1GB) from the local host to a remote host (remote_host) using a specific private key (private_key.pem):

1
scp -i private_key.pem large_file.bin user@remote_host:/path/to/destination/

In this example:

  • -i private_key.pem: Specifies the specific private key (private_key.pem) for public key authentication.
  • large_file.bin: Specifies the large file (e.g., 1GB) to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -i <identity_file> option to specify a specific private key for public key authentication during the SSH connection. The -i <identity_file> option is useful when you have multiple SSH key pairs and want to use a particular private key for authentication, allowing for flexibility and customization in your file transfer operations.

scp -l <limit>

The -l <limit> option in the scp (secure copy) command sets the limit for the maximum number of bytes per second to be copied during the file transfer. This option allows you to throttle the bandwidth used by scp, which can be useful for limiting the impact on network performance or ensuring fair usage of network resources.

Here are some advanced examples demonstrating the usage of scp with the -l <limit> option:

Example 1: Copy a File with Bandwidth Limit from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with a bandwidth limit of 500KB/s:

1
scp -l 500 example.txt user@remote_host:/path/to/destination/

In this example:

  • -l 500: Sets the bandwidth limit to 500KB/s during the file transfer.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory with Bandwidth Limit from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) with a bandwidth limit of 1MB/s:

1
scp -r -l 1000 data/ user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory data and its contents.
  • -l 1000: Sets the bandwidth limit to 1MB/s during the file transfer.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File with Bandwidth Limit and Compression from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with a bandwidth limit of 2MB/s and compression:

1
scp -l 2000 -C example.txt user@remote_host:/path/to/destination/

In this example:

  • -l 2000: Sets the bandwidth limit to 2MB/s during the file transfer.
  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy Multiple Files with Bandwidth Limit from Remote Host to Local Host

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host with a bandwidth limit of 3MB/s:

1
scp -l 3000 user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -l 3000: Sets the bandwidth limit to 3MB/s during the file transfer.
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

Example 5: Copy a Large File with Bandwidth Limit from Local Host to Remote Host

Copy a large file named large_file.bin (e.g., 1GB) from the local host to a remote host (remote_host) with a bandwidth limit of 4MB/s:

1
scp -l 4000 large_file.bin user@remote_host:/path/to/destination/

In this example:

  • -l 4000: Sets the bandwidth limit to 4MB/s during the file transfer.
  • large_file.bin: Specifies the large file (e.g., 1GB) to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -l <limit> option to set a bandwidth limit for the file transfer, allowing you to control the network usage and optimize the file transfer process based on your network conditions and requirements. The -l <limit> option is particularly useful for managing network resources, ensuring smooth and efficient file transfers without overwhelming the network or causing network congestion.

scp -B

The -B option in the scp (secure copy) command specifies batch mode, which means scp will not ask for passwords or passphrases. This is particularly useful when scp is used in scripts or when you want to automate file transfers without user interaction.

Here are some advanced examples demonstrating the usage of scp with the -B option:

Example 1: Copy a File in Batch Mode from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using batch mode:

1
scp -B example.txt user@remote_host:/path/to/destination/

In this example:

  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory in Batch Mode from Local Host to Remote Host

Copy a directory named data from the local host to a remote host (remote_host) using batch mode:

1
scp -r -B data/ user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory data and its contents.
  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • data/: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File in Batch Mode with Compression from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using batch mode and compression:

1
scp -B -C example.txt user@remote_host:/path/to/destination/

In this example:

  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • -C: Enables compression during the file transfer to reduce the size of data being transferred.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy Multiple Files in Batch Mode from Remote Host to Local Host

Copy multiple files (file1.txt, file2.txt) from a remote host (remote_host) to the local host using batch mode:

1
scp -B user@remote_host:"/path/to/file1.txt /path/to/file2.txt" /local/destination/

In this example:

  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • user@remote_host:"/path/to/file1.txt /path/to/file2.txt": Specifies the username, remote host, and paths to the files on the remote host enclosed in quotes.
  • /local/destination/: Specifies the destination directory on the local host.

Example 5: Copy a Large File in Batch Mode from Local Host to Remote Host

Copy a large file named large_file.bin (e.g., 1GB) from the local host to a remote host (remote_host) using batch mode:

1
scp -B large_file.bin user@remote_host:/path/to/destination/

In this example:

  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • large_file.bin: Specifies the large file (e.g., 1GB) to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -B option to enable batch mode, allowing you to automate file transfers without user interaction. The -B option is particularly useful when scp is used in scripts or automated workflows, providing a convenient way to transfer files securely and efficiently without manual intervention.

scp -o <ssh_option>

The -o <ssh_option> option in the scp (secure copy) command allows you to specify additional SSH options that control the behavior of the underlying SSH connection. This option provides flexibility and customization when establishing the SSH connection for the file transfer.

Here are some advanced examples demonstrating the usage of scp with the -o <ssh_option> option:

Example 1: Copy a File with Specific SSH Port from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using SSH port 2222:

1
scp -o "Port=2222" example.txt user@remote_host:/path/to/destination/

In this example:

  • -o "Port=2222": Specifies the SSH port 2222 for the underlying SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a File with SSH Compression from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using SSH compression:

1
scp -o "Compression=yes" example.txt user@remote_host:/path/to/destination/

In this example:

  • -o "Compression=yes": Enables SSH compression for the underlying SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File with SSH Key Authentication from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using a specific private key (private_key.pem) for SSH key authentication:

1
scp -o "IdentityFile=private_key.pem" example.txt user@remote_host:/path/to/destination/

In this example:

  • -o "IdentityFile=private_key.pem": Specifies the specific private key (private_key.pem) for SSH key authentication.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy a File with SSH Timeout from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with an SSH connection timeout of 30 seconds:

1
scp -o "ConnectTimeout=30" example.txt user@remote_host:/path/to/destination/

In this example:

  • -o "ConnectTimeout=30": Sets the SSH connection timeout to 30 seconds.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 5: Copy a File with SSH Logging from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) with SSH logging enabled:

1
scp -o "LogLevel=VERBOSE" example.txt user@remote_host:/path/to/destination/

In this example:

  • -o "LogLevel=VERBOSE": Sets the SSH logging level to VERBOSE.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -o <ssh_option> option to specify additional SSH options for customizing and controlling the behavior of the underlying SSH connection during the file transfer. The -o <ssh_option> option provides a powerful way to fine-tune the SSH connection settings, enabling you to optimize and secure your file transfers based on your specific requirements and network conditions.

scp -F <configfile>

The -F <configfile> option in the scp (secure copy) command allows you to specify an alternative configuration file for the SSH client. This can be useful when you want to use a custom SSH configuration file that contains specific SSH options, host configurations, or aliases.

Here are some advanced examples demonstrating the usage of scp with the -F <configfile> option:

Example 1: Copy a File Using Custom SSH Configuration from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using a custom SSH configuration file (custom_ssh_config):

1
scp -F custom_ssh_config example.txt user@remote_host:/path/to/destination/

In this example:

  • -F custom_ssh_config: Specifies the custom SSH configuration file (custom_ssh_config) to be used for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a File Using Aliases from Custom SSH Configuration from Local Host to Remote Host

Assume the custom_ssh_config file contains an alias remote_alias for the remote host. Now, copy a file named example.txt from the local host to the remote host using the alias:

1
scp -F custom_ssh_config example.txt remote_alias:/path/to/destination/

In this example:

  • -F custom_ssh_config: Specifies the custom SSH configuration file (custom_ssh_config) to be used for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • remote_alias:/path/to/destination/: Specifies the alias (remote_alias) defined in the custom SSH configuration file and the destination path on the remote host.

Example 3: Copy a File with Specific SSH Options from Custom SSH Configuration from Local Host to Remote Host

Assume the custom_ssh_config file contains specific SSH options like Port, IdentityFile, and Compression. Now, copy a file named example.txt from the local host to a remote host using these specific SSH options:

1
scp -F custom_ssh_config example.txt user@remote_host:/path/to/destination/

In this example:

  • -F custom_ssh_config: Specifies the custom SSH configuration file (custom_ssh_config) to be used for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy a File with Host Configuration from Custom SSH Configuration from Local Host to Remote Host

Assume the custom_ssh_config file contains specific host configurations like Host, HostName, User, and Port for the remote host. Now, copy a file named example.txt from the local host to the remote host using these specific host configurations:

1
scp -F custom_ssh_config example.txt user@remote_host:/path/to/destination/

In this example:

  • -F custom_ssh_config: Specifies the custom SSH configuration file (custom_ssh_config) to be used for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 5: Copy a File with Identity File from Custom SSH Configuration from Local Host to Remote Host

Assume the custom_ssh_config file specifies a specific identity file (IdentityFile) for the SSH connection. Now, copy a file named example.txt from the local host to the remote host using this specific identity file:

1
scp -F custom_ssh_config example.txt user@remote_host:/path/to/destination/

In this example:

  • -F custom_ssh_config: Specifies the custom SSH configuration file (custom_ssh_config) to be used for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -F <configfile> option to specify a custom SSH configuration file, allowing you to leverage specific SSH options, host configurations, aliases, and identity files for customizing and controlling the behavior of the underlying SSH connection during the file transfer. The -F <configfile> option provides a flexible way to manage and utilize custom SSH configurations, enabling you to optimize and secure your file transfers based on your specific requirements and environment.

scp -4

The -4 option in the scp (secure copy) command forces the use of IPv4 addresses only. This can be useful in situations where you want to ensure that only IPv4 is used for the SSH connection and file transfer, bypassing any potential issues or conflicts with IPv6.

Here are some advanced examples demonstrating the usage of scp with the -4 option:

Example 1: Copy a File Using IPv4 Address from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using IPv4 addresses only:

1
scp -4 example.txt user@remote_host:/path/to/destination/

In this example:

  • -4: Forces the use of IPv4 addresses only for the SSH connection and file transfer.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host (using IPv4 address), and destination path on the remote host.

Example 2: Copy a File Using Specific IPv4 Address from Local Host to Remote Host

Assume the remote host has both IPv4 and IPv6 addresses. Now, copy a file named example.txt from the local host to the remote host using a specific IPv4 address (192.168.1.10):

1
scp -4 example.txt user@192.168.1.10:/path/to/destination/

In this example:

  • -4: Forces the use of IPv4 addresses only for the SSH connection and file transfer.
  • example.txt: Specifies the file to be copied from the local host.
  • user@192.168.1.10:/path/to/destination/: Specifies the username, specific IPv4 address, and destination path on the remote host.

Example 3: Copy a File Using IPv4 Address with Custom SSH Configuration from Local Host to Remote Host

Assume you have a custom SSH configuration file (custom_ssh_config) that specifies the IPv4 address for the remote host. Now, copy a file named example.txt from the local host to the remote host using this custom configuration:

1
scp -4 -F custom_ssh_config example.txt user@remote_host:/path/to/destination/

In this example:

  • -4: Forces the use of IPv4 addresses only for the SSH connection and file transfer.
  • -F custom_ssh_config: Specifies the custom SSH configuration file (custom_ssh_config) to be used for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host (using IPv4 address), and destination path on the remote host.

Example 4: Copy a File Using IPv4 Address with Specific SSH Port from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using IPv4 addresses only and a specific SSH port (2222):

1
scp -4 -P 2222 example.txt user@remote_host:/path/to/destination/

In this example:

  • -4: Forces the use of IPv4 addresses only for the SSH connection and file transfer.
  • -P 2222: Specifies the specific SSH port 2222 for the underlying SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host (using IPv4 address), and destination path on the remote host.

Example 5: Copy a File Using IPv4 Address with Batch Mode from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using IPv4 addresses only and batch mode:

1
scp -4 -B example.txt user@remote_host:/path/to/destination/

In this example:

  • -4: Forces the use of IPv4 addresses only for the SSH connection and file transfer.
  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host (using IPv4 address), and destination path on the remote host.

These examples demonstrate how to use the scp command with the -4 option to force the use of IPv4 addresses only for the SSH connection and file transfer. The -4 option can be particularly useful in environments or scenarios where IPv4 compatibility is required or preferred, ensuring smooth and reliable file transfers without potential conflicts or issues related to IPv6 configurations.

scp -6

The -6 option in the scp (secure copy) command forces the use of IPv6 addresses only. This can be beneficial in situations where you want to ensure that only IPv6 is used for the SSH connection and file transfer, bypassing any potential issues or conflicts with IPv4.

Here are some advanced examples demonstrating the usage of scp with the -6 option:

Example 1: Copy a File Using IPv6 Address from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using IPv6 addresses only:

1
scp -6 example.txt user@[IPv6_address]:/path/to/destination/

In this example:

  • -6: Forces the use of IPv6 addresses only for the SSH connection and file transfer.
  • example.txt: Specifies the file to be copied from the local host.
  • user@[IPv6_address]:/path/to/destination/: Specifies the username, IPv6 address of the remote host, and destination path on the remote host.

Example 2: Copy a File Using Specific IPv6 Address from Local Host to Remote Host

Assume the remote host has both IPv4 and IPv6 addresses. Now, copy a file named example.txt from the local host to the remote host using a specific IPv6 address:

1
scp -6 example.txt user@[IPv6_address]:/path/to/destination/

In this example:

  • -6: Forces the use of IPv6 addresses only for the SSH connection and file transfer.
  • example.txt: Specifies the file to be copied from the local host.
  • user@[IPv6_address]:/path/to/destination/: Specifies the username, specific IPv6 address, and destination path on the remote host.

Example 3: Copy a File Using IPv6 Address with Custom SSH Configuration from Local Host to Remote Host

Assume you have a custom SSH configuration file (custom_ssh_config) that specifies the IPv6 address for the remote host. Now, copy a file named example.txt from the local host to the remote host using this custom configuration:

1
scp -6 -F custom_ssh_config example.txt user@[IPv6_address]:/path/to/destination/

In this example:

  • -6: Forces the use of IPv6 addresses only for the SSH connection and file transfer.
  • -F custom_ssh_config: Specifies the custom SSH configuration file (custom_ssh_config) to be used for the SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@[IPv6_address]:/path/to/destination/: Specifies the username, IPv6 address of the remote host, and destination path on the remote host.

Example 4: Copy a File Using IPv6 Address with Specific SSH Port from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using IPv6 addresses only and a specific SSH port (2222):

1
scp -6 -P 2222 example.txt user@[IPv6_address]:/path/to/destination/

In this example:

  • -6: Forces the use of IPv6 addresses only for the SSH connection and file transfer.
  • -P 2222: Specifies the specific SSH port 2222 for the underlying SSH connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@[IPv6_address]:/path/to/destination/: Specifies the username, IPv6 address of the remote host, and destination path on the remote host.

Example 5: Copy a File Using IPv6 Address with Batch Mode from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using IPv6 addresses only and batch mode:

1
scp -6 -B example.txt user@[IPv6_address]:/path/to/destination/

In this example:

  • -6: Forces the use of IPv6 addresses only for the SSH connection and file transfer.
  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • example.txt: Specifies the file to be copied from the local host.
  • user@[IPv6_address]:/path/to/destination/: Specifies the username, IPv6 address of the remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -6 option to force the use of IPv6 addresses only for the SSH connection and file transfer. The -6 option can be particularly useful in environments or scenarios where IPv6 compatibility is required or preferred, ensuring smooth and reliable file transfers without potential conflicts or issues related to IPv4 configurations.

scp -T

The -T option in the scp (secure copy) command disables the strict filename checking during recursive transfers. This can be useful when transferring directories or files with special characters in their names.

Here are some advanced examples demonstrating the usage of scp with the -T option:

Example 1: Copy a Directory with Special Characters in Filename from Local Host to Remote Host

Copy a directory named special_dir with files that have special characters in their names from the local host to a remote host (remote_host):

1
scp -rT special_dir user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory special_dir and its contents.
  • -T: Disables strict filename checking during recursive transfers.
  • special_dir: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a File with Special Characters in Filename from Local Host to Remote Host

Copy a file named special_file!.txt from the local host to a remote host (remote_host):

1
scp -T "special_file!.txt" user@remote_host:/path/to/destination/

In this example:

  • -T: Disables strict filename checking.
  • "special_file!.txt": Specifies the file with special characters in its name to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy Multiple Files with Special Characters in Filenames from Local Host to Remote Host

Copy multiple files with special characters in their names (file!.txt, file@.txt) from the local host to a remote host (remote_host):

1
scp -T "file!.txt" "file@.txt" user@remote_host:/path/to/destination/

In this example:

  • -T: Disables strict filename checking.
  • "file!.txt" "file@.txt": Specifies multiple files with special characters in their names to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy a Directory with Special Characters in Filename Using Specific SSH Port from Local Host to Remote Host

Copy a directory named special_dir with files that have special characters in their names from the local host to a remote host (remote_host) using a specific SSH port (2222):

1
scp -rT -P 2222 special_dir user@remote_host:/path/to/destination/

In this example:

  • -r: Recursively copy the directory special_dir and its contents.
  • -T: Disables strict filename checking.
  • -P 2222: Specifies the specific SSH port 2222 for the underlying SSH connection.
  • special_dir: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 5: Copy a File with Special Characters in Filename Using Batch Mode from Local Host to Remote Host

Copy a file named special_file!.txt from the local host to a remote host (remote_host) using batch mode:

1
scp -T -B "special_file!.txt" user@remote_host:/path/to/destination/

In this example:

  • -T: Disables strict filename checking.
  • -B: Enables batch mode, which means scp will not ask for passwords or passphrases.
  • "special_file!.txt": Specifies the file with special characters in its name to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -T option to disable strict filename checking, allowing you to transfer directories or files with special characters in their names without encountering issues. The -T option provides flexibility and convenience when dealing with unique filenames, ensuring smooth and reliable file transfers in various scenarios and environments.

scp -S <program>

The -S <program> option in the scp (secure copy) command allows you to specify a program to use for the encrypted connection instead of the default SSH. This can be useful when you want to use a different protocol or tool for the secure file transfer.

Here are some advanced examples demonstrating the usage of scp with the -S <program> option:

Example 1: Copy a File Using nc (Netcat) for Encrypted Connection from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using nc (Netcat) for the encrypted connection:

1
scp -S "nc -w 3 %h %p" example.txt user@remote_host:/path/to/destination/

In this example:

  • -S "nc -w 3 %h %p": Specifies nc (Netcat) with a timeout (-w 3) as the program to use for the encrypted connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 2: Copy a Directory Using ssh with Different Port from Local Host to Remote Host

Copy a directory named data_dir from the local host to a remote host (remote_host) using ssh with a different port (2222) for the encrypted connection:

1
scp -S "ssh -p 2222" -r data_dir user@remote_host:/path/to/destination/

In this example:

  • -S "ssh -p 2222": Specifies ssh with a different port (-p 2222) as the program to use for the encrypted connection.
  • -r: Recursively copy the directory data_dir and its contents.
  • data_dir: Specifies the directory to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 3: Copy a File Using openssl for Encrypted Connection from Local Host to Remote Host

Copy a file named secure_file.txt from the local host to a remote host (remote_host) using openssl for the encrypted connection:

1
scp -S "openssl s_client -connect %h:%p" secure_file.txt user@remote_host:/path/to/destination/

In this example:

  • -S "openssl s_client -connect %h:%p": Specifies openssl with s_client to establish the encrypted connection.
  • secure_file.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 4: Copy a File Using telnet for Encrypted Connection from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using telnet for the encrypted connection:

1
scp -S "telnet %h %p" example.txt user@remote_host:/path/to/destination/

In this example:

  • -S "telnet %h %p": Specifies telnet as the program to use for the encrypted connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

Example 5: Copy a File Using ssh with Specific Identity File from Local Host to Remote Host

Copy a file named example.txt from the local host to a remote host (remote_host) using ssh with a specific identity file (id_rsa) for the encrypted connection:

1
scp -S "ssh -i id_rsa" example.txt user@remote_host:/path/to/destination/

In this example:

  • -S "ssh -i id_rsa": Specifies ssh with a specific identity file (-i id_rsa) as the program to use for the encrypted connection.
  • example.txt: Specifies the file to be copied from the local host.
  • user@remote_host:/path/to/destination/: Specifies the username, remote host, and destination path on the remote host.

These examples demonstrate how to use the scp command with the -S <program> option to specify a program for the encrypted connection, allowing you to leverage different protocols or tools for secure file transfers based on your specific requirements and environment. The -S <program> option provides flexibility and customization, enabling you to optimize and secure your file transfers using alternative methods or protocols in various scenarios and configurations.

This post is licensed under CC BY 4.0 by the author.