Transfer files securely using SCP [Linux]

Transfer files securely using SCP [Linux]

When accessing a Linux server, you have a few options. If it is a server with a UI, you can use VNC, but the most common option is to connect to a headless server with Secure Shell or SSH. It is an encrypted and secure protocol that gives you access to a remote system through an SSH client. However, you might just want to send some files to a server. You can do this by using a program called Secure Copy, or SCP, which runs over robust SSH protocol to quickly transfer files over your network to a remote system. Here we show you how to transfer files securely using SCP in Linux.

Configure SSH

On your server (or any other remote system you want to access), you will need to install an SSH server. The most common server in Linux is the OpenSSH server. To install it, you can run one of the following commands:

Installation of Scp Dnf

Depending on your distribution, you may need to allow SSH through some software firewalls. On Ubuntu this problem is nonexistent, but on CentOS you will also need to run the following commands:

SCP Firewall Cmd Add ServiceSCP Firewall Cmd Add Service
Reloading the Scp Firewall CmdReloading the Scp Firewall Cmd

At this point you will need an SSH client. On most distributions, the OpenSSH client is installed. But if you don’t, install it with the following command:

Connecting to your system via SSH

Let’s make sure SSH is working before we try to play with SCP. Before you can connect using SSH, you need to find out the server’s IP address. On graphics servers, the IP address is displayed in the Network applet in the system settings. On most servers, you should use the ip command on the terminal.

SCP server IPSCP server IP

In the output, find the line starting with inet under eth0 or enp1s0, depending on how your network interface is connected to the system. In my case, it’s

READ:   How to install fonts in Ubuntu 20.04

To test the SSH connection, go to the Linux client machine and type:

Replace “user” with the actual user name on the server.

Scp Ssh test clientScp Ssh test client

Enter the password for this account and you are in business. If you receive a question about “the authenticity of the host cannot be established”, simply answer “yes” to the question. This is a security check designed to ensure that you are connecting to your real server and not to an impostor. You should see the same prompt appear on your client system that you see when you connect directly to the server, which means your connection was successful. You should also configure your SSH connections for maximum security before proceeding to the next step.

Using SCP to transfer files

Now that you have tested the SSH connection, you can start copying files between the two machines. The secure copy is performed using the scp order. The basic format of scp the command is:

For example, to copy the “backup.txz” file from the local machine to the “backups” folder in the home directory of the “maketecheasier” user on the remote server with the IP address, use:

Scp testScp test

Similar to when you log in using ssh, you will be prompted to enter the password. You will not be prompted for the username, as specified in the command.

You can also use wildcard characters like the following:

To copy a file from the remote server to the local machine, just reverse the settings:

Note the period at the end of the command which means “the current directory”, as it does with the standard cp or mv orders. You can just as easily specify another directory if you wish.

And the same with the jokers:

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

And to copy a recursive copy of a directory from the remote server to the local machine, use:

Other SCP commands to try

To progress further, try to experience the -C , which allows compression when copying or -l option, which limits the bandwidth when copying.

READ:   LXDE exam: light as a feather

To transfer a file without having to type a password each time, you can also generate a private SSH key to connect to your server.


John perkins
John perkins

John is a young technical professional passionate about educating users on the best ways to use their technology. He holds technical certifications covering subjects ranging from computer hardware to cybersecurity to Linux system administration.

Is this article useful?

s.parentNode.insertBefore(t,s)}(window, document,’script’,
fbq(‘init’, ‘400239050508508’);
fbq(‘track’, ‘PageView’);

file transferLinuxscpssh

More Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed