This article is going to show you that how to use scp command in Linux. If you want to learn Securely Transfer Files Using SCP Command in Linux then this article is best for you.
Linux SCP stands for Secure Copy Protocol. It is a method of encrypting the transmission of files from local server to remote server, from remote server to local server, or between two remote hosts. It is a secure variant of the cp (copy) command. SCP includes encryption over an SSH (Secure Shell) connection.
When you transferring files using SCP Command, both the files and password are encrypted so that any snooper does not get any sensitive information.
SCP Command Syntax
All SCP commands follow the below basic syntax :
$ scp [OPTIONS] [SOURCE] [DESTINATION]
Transferring a Local File to a Remote System using the scp
Command
To transferring a file from a local system to a remote system, use the local system location as the source and remote server location as a destination.
$ scp path/to/local/file.txt user@remote-host:path/to/remote/file.txt
Here,
file.txt
is the name of the file that we want to transferuser
is the username on the remote server- remote-host is the domain name or the IP address of the remote machine
When you run above command, a prompt will be displayed to enter the user password, and the transfer process will start.
Transferring a Remote File to a Local System using the scp
Command
To transferring a file from a remote system to a local system, use the remote server location as a source and local system location as the destination.
$ scp user@remote-host:path/to/remote/file.ext path/to/local/file.ext
Here,
file.txt
is the name of the file that we want to transferuser
is the username on the remote server- remote-host is the domain name or the IP address of the remote machine
# Example :
To copy or transfer a file named file.txt
from a remote server with IP 20.20.0.2
run the below command:
scp remote_username@20.20.0.2:path/to/remote/file.txt path/to/local/file.txt
When you run above command, a prompt will be displayed for the password belongs to the remote host’s user account.
Transferring a Remote File to a Remote Destination using the scp
Command
$ scp user1@remote-host1:path/to/remote/file.ext user2@remote-host2:path/to/remote/file.ext
The above command is used to transfer a file between two remote hosts.
Here,
file.txt
is the name of the file that we want to transferuser
1 is the username of the Source remote server- remote-host1 is the domain name or the IP address of the Source remote machine
user
2 is the username of the Destination remote server- remote-host2 is the domain name or the IP address of the Destination remote machine
When you run above command, a prompt will be displayed to enter the passwords for both remote accounts. The file will be transfer directly from one remote host to the other remote host.
That’s all
If you find any error and issue in the above steps , please use below comment box to report.