Want to transfer files between two Ubuntu servers? If you ever needed to transfer files quickly between two Ubuntu servers, the best way to it is via SSH using Secure Copy (SCP).
SCP uses SSH encryption and authentication to securely transfer files between servers quickly and easily. This brief tutorial is going to show students and new users how to use SCP via SSH to transfer files between two Ubuntu servers.
Secure copy is a means of securely transferring files between a local host computer and a remotely host or between two computers via SSH protocol.
Below are examples of how to use SCP to copy to / from hosts.
Transferring files to a remote host
To transfer a file to a remote server from the local server you’re currently logged into, run the example commands below.
scp file_to_transfer.txt firstname.lastname@example.org:/directory_to_drop_file/location/
The commands above copies a local file from the local server and transfers it to a remote server via the remote server’s hostname or IP address and dropping it into the directory location specified.
Transferring files from a remote host
To transfer files from a remote host to a local server, you use the example commands below. Let’s say you want to copy your entire website content in a zipped folder called website_content.zip.
You run the commands below to copy the content from the remote server to the local host.
scp email@example.com:/directory/website_content.zip /path_to_store_content/www/html/website_content.zip
Doing the above will copy the remote content to the local host securely. Replace remotehost.com with the hostname of IP address of the remote server. Also, replace root with the actual admin account of the server.
For some reasons, if SSH default port is changed from 22, you may have to specify the new port when using the commands above. The example command is shown below.
scp -P 2221 local_file.txt username@remotehost:/directory/location/
Do the same when copying files from the remote host to the local server.
This post shows students and new users how to use SCP via SSH to securely and quickly transfer files between a local host and a remote server. SCP uses SSH encryption and authentication to protect the content being transferred.
So, if you ever needed to transfer sensitive content between two Ubuntu hosts, follow the steps above to get it done.
You may also like the post below: