06.12.2024

How to Use SCP Debian Command to Securely Transfer Files?

Introduction

Encrypting sensitive data before transferring it is essential to maintain its confidentiality, integrity, and authenticity during transmission. Encryption transforms the data into a secure format that can only be understood by authorized parties with the correct decryption key. This prevents unauthorized individuals and hackers from intercepting and deciphering the sensitive data while it travels.

Moreover, encryption acts as an additional layer of security, safeguarding sensitive information like personal data, financial details, or intellectual property from unauthorized access and eavesdropping. When data is transmitted over unsecured channels like the internet, encryption becomes crucial in mitigating risks associated with interception and data breaches. For solve that task we have SCP.

SCP -  is a utility in the UNIX-like systems that allows you to copy files and directories between local and remote hosts over a secure SSH protocol.

Overall, using encryption, such as through utilities like SCP, instills peace of mind for both senders and recipients. They can be assured that their sensitive information is shielded from unauthorized access and manipulation. Embracing encryption is a fundamental practice for secure data communication in today's computing landscape.

Requirements

Installation

For the securely transfer we think more complex about our guard system and we need to update, upgrade all packages before using utility:

apt update && apt upgrade -y

Screenshot №1 — Update OS

After that, we need to check the repository list and packages. If you are certain that your system meets all requirements, you can skip this step. However, if you haven't done that yet, enter the following CLI command:

apt list | grep scp && scp

Screenshot №2 — Check installation

In the picture above we can see amount packages and using the written command, we can check the currently installing package. Let's have a look at the syntax of that command:

scp [-346ABCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file] [-] destination] [-l limit] [-o ssh_option] [-P port] [-S program] source… target

At the above we consider all options and parameters which get utility in usage. Let's consider different way to use that utility.

Usual transfer file

Utility allows us to move securely file between different machines. For that we need type in the CLI command:

scp /etc/apple.txt root@78.140.240.178:/etc/

Screenshot №3 — Usual transfer

Enter your credentials in the form user, IP, password and agree with connect. Good job! Now we can find that in the target machine the same file via command below:

cd /etc && ls

Screenshot №4 — List of the files

In the firts column apple.txt successful transfered between two systems via ssh! If you want to send whole folder or directory, use -r options, let's have a look to the example of that:

scp -r -C -4 /etc/network root@78.140.240.178:/dump

Screenshot №5 — List of the files

The feature of that program can be used for backup purposes, transfering start with simple file and finished ISO of whole disk and system. Fortunately, Linux system have settings in the config file. which transfer without any problem. Also we can use reverse connect and transfer file from remote machine to local, just switch them. Consider different way to transfer below.

Archive backup

Wiht SCP we can create archive of all disk, system data base and another things that can contain amount of data. Have a look at the bundle of tar and scp, how to transfer this type of data? Additional many company use non standart port for SSH connection, let's change on the target machine port to 2222 and consider how to communicate in that situations. Write commands below:

tar -cvzf dump.tar.gz / && ls

Screenshot №6 — Archive file

Make sure that file will archive and write this command bellow:

scp -4 -C -v -P 2222 dump.tar.gz root@78.140.240.178:/

Screenshot №7 — Sended tar

Now, we need to unzip folder and use it for our purposes via command below:

mkdir dump && tar -xvf dump.tar.gz -C /dump

We create folder and extract all content in the folder:

Screenshot №8 — Unzip

Transfer dd image of disk

Please make sure that you have sufficient permissions to access the source image file and write to the destination directory. Also, keep in mind that transferring large DD image files may take some time, depending on your network connection and the size of the image. Before we create ISO image of entire system you need to discover your storage parameters via command below:

lsblk

Screenshot №9 — List of disk

In our case we can see one physical drive and two logical space for our manipulating which we use to create ISO image:

dd if=/dev/vda1 of=dump.iso bs=4M status=progress

Screenshot №10 — Make ISO

After successful creation of image file we can transfer that by the previous way:

scp -4 -C -v -P 2222 /dump.iso root@78.140.240.178:/tmp

Screenshot №11 — Connection

Conclusion

In conclusion, encrypting sensitive data during transmission is paramount for data security. SCP, a utility available in UNIX-like systems, plays a crucial role in facilitating secure file and directory transfers between local and remote hosts using the SSH protocol. Encryption through tools like SCP instills confidence in both senders and recipients, ensuring that sensitive information is protected from unauthorized access and manipulation. Embracing encryption is not only a best practice but an essential component of secure data communication in today's computing landscape.