Knowledgebase
Transferring content between two Linux servers can seem daunting if you're new to Linux. This guide will walk you through using the scp command (specifically on Ubuntu) to send files or entire directories from one Ubuntu server to another. Don’t worry, it’s simpler than you think!
Table of Contents
The scp (secure copy) command in Linux is used to securely transfer files or directories between systems over SSH. It works similarly to the cp command but allows copying to or from remote machines, with all data encrypted during transfer.
While there are other tools like rsync for transferring files between servers, scp is straightforward and reliable, perfect for simple tasks. This guide keeps things beginner-friendly by focusing on scp.
To transfer content between two servers, you’ll need the SSH connection details for both machines. Let’s assume there’s "Server 1" and "Server 2", and you want to transfer content from Server 1 to Server 2.
Run the below command on Server 1 (the source), replacing the placeholders in the command with the actual details of server 2.
scp /path/to/local.file SERVER_2_USERNAME@SERVER_2_IP:/path/to/save.fileExample
scp /var/www/html/index.html root@123.321.789.1:/var/www/html/index.htmlTo transfer an entire folder and its contents, for example the entire /home folder, add the recursive flag (-r) to the command
scp -r /home SERVER_2_USERNAME@SERVER_2_IP:/homeExample
scp -r /home root@123.321.789.1:/homeWhen you run these commands, you may be prompted to confirm the server’s fingerprint and enter Server 2’s password. Once authenticated, the transfer will begin, and progress will be shown in your terminal.
And that’s it! You’ve successfully transferred files or directories between Ubuntu servers using SCP.