SCP Command - Secure File Copy
Understanding the SCP Command
The SCP (Secure Copy Protocol) command is a fundamental utility for securely transferring files between hosts on a network. It leverages SSH (Secure Shell) for data transfer, ensuring that your files are encrypted during transit. This makes it an essential tool for developers and system administrators who need to move data between local and remote servers.
Common SCP Usage Examples
Here are some of the most frequent ways to use the SCP command:
Copying a File from Local to Remote
To copy a file from your local machine to a remote server, use the following syntax:
scp <local_file_path> <user>@<remote_host>:<remote_destination_path>
Replace <local_file_path> with the path to the
file on your local system, <user> with your
username on the remote server, <remote_host> with
the hostname or IP address of the remote server, and
<remote_destination_path> with the directory
where you want to save the file on the remote server.
Copying a File from Remote to Local
To retrieve a file from a remote server to your local machine, use this command:
scp <user>@<remote_host>:<remote_source_path> <local_destination_path>
Here, <remote_source_path> is the path to the
file on the remote server, and
<local_destination_path> is where you want to
save it on your local machine.
Using SCP with a SOCKS Proxy
If you need to route your SCP traffic through a SOCKS proxy, you can specify the proxy command. This is often used in conjunction with SSH tunneling.
scp -o "ProxyCommand nc -x 127.0.0.1:9999 -X 4 %h %p" <file> <user>@<host>:<dest>
In this example, 127.0.0.1:9999 represents the SOCKS
proxy address and port.
Copying Files Between Two Remote Servers
SCP also allows you to copy files directly between two remote
servers from a third machine. This is achieved using the
-3 option.
scp -3 <user1>@<host1>:<src> <user2>@<host2>:<dest>
This command copies the file from host1 to
host2, with the transfer being relayed through your
current machine.