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:
# Debian/Ubuntu-based server sudo apt install openssh-server # Fedora/Centos sudo dnf install openssh-server
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:
sudo firewall-cmd --add-service=ssh --permanent sudo firewall-cmd --reload


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:
# Debian/Ubuntu-based distro sudo apt install openssh-client # Fedora sudo dnf install openssh-client
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.

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 192.168.122.201.
To test the SSH connection, go to the Linux client machine and type:
Replace “user” with the actual user name on the server.

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:
scp /PATH/TO/FILE USER@IP-ADDRESS:PATH/TO/DESIRED/DESTINATION
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 192.168.1.101, use:
scp backup.txz maketecheasier@192.168.122.201:~/backups/

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:
scp *.txz maketecheasier@192.168.122.201:~/backups/
To copy a file from the remote server to the local machine, just reverse the settings:
scp maketecheasier@192.168.122.201:~/backups/backup.txz .
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.
scp -r maketecheasier@192.168.122.201:~/backups/ backups-from-server/
And the same with the jokers:
scp maketecheasier@192.168.122.201:~/backups/*.txz .
To recursively copy a directory to a remote server, use the -r
option:
scp -r backups/ maketecheasier@192.168.122.201:~/backups/
And to copy a recursive copy of a directory from the remote server to the local machine, use:
scp -r scp -r maketecheasier@192.168.122.201:~/backups/ .
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.
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.
Related:
Is this article useful?
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version=’2.0′;
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,’script’,
‘https://connect.facebook.net/en_US/fbevents.js’);
fbq(‘init’, ‘400239050508508’);
fbq(‘track’, ‘PageView’);