Securely copy files over SSH in Linux. scp command.

Securely copy files over SSH in Linux. scp command.

Colleagues hello to all.

In today's article, we'll talk about how to securely transfer files from one server to another on Linux. For this purpose, we will use a utility called SCP, the full name of the secure copy utility. The SCP util in Linux allows you to securely copy files and directories between two locations. The SCP utility encrypts the connection and ensures that even if the data is intercepted, it will be protected.

 

Article content:

  1. Syntax for scp.
  2. Transfer file from local server to remote server.
  3. Transfer file from local server to remote server with different port.
  4. Transfer file from remote server to local server.
  5. Moving directory in local server to remote server.
  6. Transfer file and directory with compression.

 

1. Syntax of the scp command.

scp [options] destination source

  • source - the file or directory we want to transfer.
  • destinations - the place where we want to transfer.

 

2. Transferring a file from a local server to a remote server.

We ssh the local file mysql-commercial-backup.rpm from server 192.168.2.229 to server 192.168.2.230 in the /root directory.

$. scp mysql-commercial-backup.rpm root@192.168.2.230:/root

linux_command_scp


 

3. Transferring a file from a local server to a remote server with a different port.

You can transfer files using other ports, for this you need to add the parameter (-p). In this case, I will transfer the file using port 6884.

$. scp -p 6884 mysql-commercial-backup.rpm root@192.168.2.230:/root

linux_command_scp


 

4. Transferring a file from a remote server to a local server.

Now it's the other way around. We move the file from the remote server 192.168.2.230 to our server 192.168.2.229.

$. scp root@192.168.2.230:/root/test_scp.sh /root

linux_command_scp


 

5. Moving a directory from a local server to a remote server.

In this case, we will be transferring the  test_scp directory from server 192.168.2.229 to a remote server 192.168.2.230. To do this, use the (-r) parameter.

$. scp -r /root/test_scp root@192.168.2.230:/root

linux_command_scp


 

6. Transfer file and directory with compression.

For large files and directories, you can use compression during transfer, for this you need to use the (-C) parameter. Compression is performed only during transfer, which means that the resulting file will be in its original form.

$. scp -C mysql-commercial-backup.rpm root@192.168.2.230:/root

linux_command_scp


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

tar utility - how to zip and unzip files in linux
tar utility - how to zip and unzip files in linux
LINUX
Read more
How to find out the size of a file and directory in Linux
How to find out the size of a file and directory in Linux
LINUX
Read more
bzip2 utility - how to compress and decompress files in Linux
bzip2 utility - how to compress and decompress files in Linux
LINUX
Read more