bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Bash/Networking
Bash•Networking

Bash scp Command - Secure Copy

Using the scp Command

The scp command is used to securely copy files between hosts on a network.

Basic Usage

To copy a file to a remote host, use scp file user@hostname:/path :

Example

scp file.txt user@example.com:/home/user/
user@example.com's password:
file.txt

Options

The scp command supports various options to customize its behavior:

  • -r - Recursively copy entire directories
  • -P - Specify the port to connect to on the remote host
  • -i - Specify an identity (private key) file
  • -C - Enable compression
  • -v - Enable verbose mode
  • -l - Limit the bandwidth used by the copy

Option: -r (Recursive Copy)

The -r option allows you to recursively copy entire directories.

Example: Recursive Copy

scp -r /path/to/directory user@example.com:/home/user/
user@example.com's password:
1.png 100% 1797KB 2.7MB/s 00:00
2.png 100% 1873KB 3.2MB/s 00:00
3.png 100% 1808KB 3.9MB/s 00:00
...

Option: -P (Port)

The -P option allows you to specify a port to connect to on the remote host.

By default, SCP uses port 22.

Example: Specify Port

scp -P 2222 file.txt user@example.com:/home/user/
user@example.com's password:
file.txt

Option: -i (Identity File)

The -i option allows you to specify a private key file for authentication.

This is useful when you have a specific key for a server.

Example: Use Private Key

scp -i /path/to/private_key file.txt user@example.com:/home/user/
file.txt

Option: -C (Compression)

The -C option enables compression, which can speed up file transfer by reducing the amount of data sent over the network.

Example: Enable Compression

scp -C file.txt user@example.com:/home/user/
user@example.com's password:
file.txt

Option: -v (Verbose Mode)

The -v option enables verbose mode, providing detailed output about the file transfer process.

This is helpful for debugging.

Example: Verbose Mode

scp -v file.txt user@example.com:/home/user/
Executing: program /usr/bin/ssh host example.com, user user, command scp -v -t /home/user/
file.txt 100% 1234KB 1.2MB/s 00:01
...

Option: -l (Limit Bandwidth)

The -l option allows you to limit the bandwidth used by the copy. This is useful for managing network resources.

Example: Limit Bandwidth

scp -l 100 file.txt user@example.com:/home/user/
user@example.com's password:
file.txt

Understanding SCP Output

The output of the scp command will vary depending on the options used. Here are some common elements:

  • Transfer Progress: Shows progress of the file transfer.
  • File Size: The size of the file being transferred.
  • Transfer Speed: The speed at which the file is being transferred.
  • Time Remaining: Estimated time remaining for the transfer to complete.

Previous

Bash ssh Command - OpenSSH SSH Client

Next

Bash rsync Command - Remote (and local) File-copying

This chapter

Overview
6

Lessons

19m

Read time

1. Bash ping Command - Send Request to Network Hosts2. Bash curl Command - Transfer a URL3. Bash wget Command - Non-Interactive Network Downloader4. Bash ssh Command - OpenSSH SSH Client5. Bash scp Command - Secure Copy6. Bash rsync Command - Remote (and local) File-copying

On this page

Using the scp CommandBasic UsageOptionsOption: -r (Recursive Copy)Example: Recursive CopyOption: -P (Port)Example: Specify PortOption: -i (Identity File)Example: Use Private KeyOption: -C (Compression)Example: Enable CompressionOption: -v (Verbose Mode)Example: Verbose ModeOption: -l (Limit Bandwidth)Example: Limit BandwidthUnderstanding SCP Output