Bash scp
- Secure Copy (remote file copy program)
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 [email protected]:/home/user/
[email protected]'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 [email protected]:/home/user/
[email protected]'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 [email protected]:/home/user/
[email protected]'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 [email protected]:/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 [email protected]:/home/user/
[email protected]'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 [email protected]:/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 [email protected]:/home/user/
[email protected]'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.