Janna Theme License is not validated, go to the theme options page to validate the license, you need a single license for each domain name.

How to Securely Transfer Files in Linux Using SCP

When transferring files to a remote Linux server, you have a few options. One of the best ways is to use a program called Secure Copy, or SCP, which runs over the SSH protocol to quickly transfer files across your network to a remote system. This tutorial shows you how to securely transfer files in Linux using SCP.

scp-transfer-linux-00-featured-image-800x400.jpg How to Securely Transfer Files in Linux Using SCP

SSH configuration

On your remote server, you'll need to install an SSH server. The most common on Linux is OpenSSH. To install it, run one of the following commands:

# Debian/Ubuntu-based server sudo apt install ssh # Fedora sudo dnf install openssh

scp-transfer-linux-01-installing-ssh.png How to Securely Transfer Files in Linux Using SCP

Depending on your distribution, you may need to allow SSH through some software firewalls. In Ubuntu, this problem doesn't exist, but in Fedora You will also have to run the following commands:

sudo firewall-cmd --add-service=ssh --permanent sudo firewall-cmd --reload

scp-transfer-linux-02-fedora-enable-firewall.png How to securely transfer files in Linux using SCP

Connect to your system via SSH

Before you can connect via SSH, you need to know the IP address of the remote server. On graphical servers, the IP address appears in the Network applet in the system settings. On most servers, you must use the ip command on the terminal.

IP addr

scp-transfer-linux-04-check-ip-address.png How to Securely Transfer Files in Linux Using SCP

In the output, find the line that starts with inet within ethX Or enpXsy , depending on how your network interface connects to the system. In my case, it's 192.168.68.108.

to test SSH connection Go to device Linux Different and write:

change "user" To User name Actual on server.

scp-transfer-linux-05-connecting-to-remote-server.png How to Securely Transfer Files in Linux Using SCP

Enter password This account, and you are working. If you receive a question about “Host authenticity cannot be proven” So, just answer with "Yes". This is a security check designed to ensure that you are connecting to your actual server and not a fraudulent one. You should see the same prompt on your client system that you see when logging directly to the server, indicating that your connection was successful. You should also configure SSH connections for maximum security, or even Set up two-factor authentication , before proceeding to the next step.

Also read:  Why Neovim is the best choice for text editing on Linux

Using SCP to transfer files

Now that you've tested your SSH connection, start copying files between the two machines. Secure copying is accomplished using the scp command. The basic format of the scp command is:

scp /PATH/TO/FILE USER@IP-ADDRESS:PATH/TO/DESIRED/DESTINATION

For example, to copy a file “backup.tar.gz” From local machine to folder “backup.tar.gz” In the user's home directory Ramses On the remote server with the address IP 192.168.68.165 Use:

scp backup.tar.gz [email protected]:~/backups/

scp-transfer-linux-06-basic-copying.png How to Securely Transfer Files in Linux Using SCP

Similar to when connecting using SSH, you will be prompted for your password. You will not be prompted for your username, as specified in the command.

You can also use wildcards like the following:

scp *.tar.gz [email protected]:~/backups/

scp-transfer-linux-07-glob-matching-copy.png How to Securely Transfer Files in Linux Using SCP

To copy a file from the remote server to the local machine, simply reverse the parameters:

scp [email protected]:~/backups/backup.tar.gz ./

scp-transfer-linux-08-inverse-copying.png How to Securely Transfer Files in Linux Using SCP

Notice the dot at the end? It means Current Volume , as with Standard cp commands Or etc. You can easily specify another directory if you want.

scp -r [email protected]:~/backups/backups-from-server/

Same thing with wild cards:

scp [email protected]:~/backups/*.txz ./

To repeatedly copy a directory to a remote server, use -r option:

scp -r backups/ [email protected]:~/backups/

scp-transfer-linux-09-recursive-copying.png How to Securely Transfer Files in Linux Using SCP

To copy a duplicate copy of a directory from the remote server to the local machine, use:

scp -r [email protected]:~/backups/ ./

scp-transfer-linux-10-reverse-recursive-copying.png How to Securely Transfer Files in Linux Using SCP

File transfer compression in SCP

Aside from basic copying, it is also possible to modify SCP's behavior during these file transfers. For example, you can use the flag -C To compress data that SCP sends to remote clients:

scp -C backup.tar.gz [email protected]:/home/ramces/

This option works by compressing each data packet as it is sent through the SCP program. As such, this can be incredibly useful if you're on a limited bandwidth connection and want to reliably send a file to a remote server.

scp-transfer-linux-11-data-compression-copy.png How to Securely Transfer Files in Linux Using SCP

Similar to the options above, you can also use -C Along with the mark -r To compress files and transfer them repeatedly to a remote device. For example, the following command compresses and retrieves a file: “backup.tar.gz” From my distant servant:

scp -Cr [email protected]:/home/ramces/backups /home/ramces/

scp-transfer-linux-12-reverse-data-compression-copy.png How to Securely Transfer Files in Linux Using SCP

Improve data transfer using SCP

For the most part, SCP tries to use encryption algorithm AES-128 For all its file transfer operations. However, there are cases where this particular algorithm may not be suitable for the files you want to transfer.

Also read:  How to Make Ubuntu Look Like macOS Big Sur

Knowing this, it is possible to further improve and secure SCP by directly changing the encryption algorithm for a specific transmission. To do this, you need to use the tag -c Followed by the code you want to use.

For example, the following command moves a file: “backup.tar.gz” to my remote server using AES-256:

scp -c aes256-ctr ./backup.tar.gz [email protected]:/home/ramces/

scp-transfer-linux-13-change-default-cipher.png How to securely transfer files in Linux using SCP

Moreover, the option allows you to -c Also provide a list of the zeros you want to use to move a particular file. For example, the following command uses both AES-192 و AES-256 While transferring a file “backup.tar.gz” To my distant servant:

scp -c aes192-ctr,aes256-ctr ./backup.tar.gz [email protected]:/home/ramces/

scp-transfer-linux-14-create-cipher-preference-list.png How to transfer files securely in Linux using SCP

Limit bandwidth usage in SCP

While compressing file packets can help you use SCP in poor network conditions, it's also possible to limit the bandwidth the program uses during transmission. This is useful in situations where you're using a limited connection and don't want SCP to hog your network bandwidth.

To limit the effective bandwidth of the program, you need to use -l mark followed by the maximum you want In kilobits per second (Kb/s). For example, running the following command will move a file: “backup.tar.gz” To my remote server with an effective bandwidth of 1600 Kb/s:

scp -l 1600 ./backup.tar.gz [email protected]:/home/ramces/

scp-transfer-linux-15-limit-bandwidth-during-copy.png How to Securely Transfer Files in Linux Using SCP

Remote to Remote with SCP

Aside from copying local files to your remote server and vice versa, you can also use SCP to manage multiple remote servers from your local machine, because SCP only handles file transfer and does not distinguish between a local and a remote machine.

To transfer between two remote servers, you need to explicitly specify the username and address of each of these machines. For example, running the following command will transfer a file: “remote-backup.tar.gz” My between two remote servers:

scp [email protected]:/home/ramces/remote-backup.tar.gz [email protected]:/home/ramces/

scp-transfer-linux-16-remote-to-remote-copy.png How to Securely Transfer Files in Linux Using SCP

Using a proxy with SCP

By default, SCP uses your local machine's IP address when transferring files between different hosts. While this is perfectly fine in normal situations, it can be problematic if your local network restricts any SCP activity. One quick way to deal with this is to route your local connection through an SSH proxy.

To do this, you need to use the tag -o followed by an option ProxyCommand. This allows you to create a basic SSH connection to a new device that will then execute your SCP command. For example, running the following will create a new SSH agent on a remote device and transfer a file “backup.tar.gz” Using it:

scp -o "ProxyCommand ssh [email protected] nc %h %p" ./backup.tar.gz [email protected]:/home/ramces/

scp-transfer-linux-17-ssh-proxy-bypass.png How to Securely Transfer Files in Linux Using SCP

Change the default port in SCP

In addition to creating a basic SSH proxy, you can also change the default port for SCP. This is especially useful if you're securing a Linux server and don't want to expose any default ports.

Also read:  How to install Slack on Linux easily

To use SCP with a different port, you need to use the flag -P followed by the port number you want to use. For example, the following command will copy the directory "Backup" Frequently connect to the remote server using the port 2222:

scp -r -P 2222 ./backup [email protected]:/home/ramces/

scp-transfer-linux-18-using-custom-port.png How to Securely Transfer Files in Linux Using SCP

Use SCP Quiet Mode

Finally, it's also possible to completely remove any terminal output from an SCP command. This is particularly useful if you want to create a non-interactive script that runs on your device. Not only that, but you can also automate this entire process by creating cron job and transfer SSH key Private to your server.

To create a quiet SCP transport, you need to use the tag -qFor example, the following command will move the file: “backup.tar.gz” My silently to my distant servant:

scp -q ./backup.tar.gz [email protected]:/home/ramces/

scp-transfer-linux-19-quiet-mode.png How to Securely Transfer Files in Linux Using SCP

Frequently Asked Questions

Q1. My remote control for teleportation isn't working in SCP. How can I fix this?
answer. This issue is often caused by a blocked port in one of your remote machine's configuration files. To fix this, ensure that the default SSH port is open on both machines.

This issue can also occur because one of your remote devices is behind a CG-NAT connection, so any external connections to your remote device will not resolve properly. To resolve this issue, you need to use VLAN software , Such as Yggdrasil , which will allow you to pass through CG-NAT.

Q2. I turned on the SCP proxy and the remote host closed the connection. What can I do?
answer. This issue is most likely caused by a problem with your proxy machine. To start the SSH proxy correctly, make sure that the machine you want to use has an OpenSSH server and netcat installed. To install these programs, Ubuntu, Run the following command: sudo apt install ssh netcat.

Q3. Is it possible to know all the ciphers available for SCP?
answer. By default, the SCP program relies heavily on the SSH protocol for its encryption functions. For this reason, you can use an SSH program to print a list of ciphers that you can use in conjunction with SCP. For example, you can run ssh -Q ciphers To print a short list of all the codes available on your device.

Go to top button