How to Upload Files to Remote System Over SSH (2024)

Sooner or later, you'll find yourself in a situation where you have to upload the file to the remote server over SSH or copy a file from it.

There are various ways you can transfer files over SSH. I am going to discuss the following methods here:

  1. scp: Legacy command which is being deprecated
  2. rsync: Popular command for file synchronization
  3. sshfs: Mounting remote directory over SSH
  4. sftp clients: GUI tool for accessing file over SFTP

For a successful file transfer over SSH, you need to

  • have SSH access between the two machines
  • know the username and password on the remote machine
  • know the IP address or hostname (on the same subnet) of the remote machine

With that aside, let's see the methods for copying files between remote systems via SSH.

Method 1: Use scp command to copy files over SSH

I have read that scp is going to be deprecated. Still, it is my favorite tool for transferring files between systems over SSH. Why? Because its syntax is similar to the cp command.

Let's see how to use the scp command.

Copy files from the remote machine to your local machine

How to Upload Files to Remote System Over SSH (1)

Here's the scenario. You want to copy files from the remote Linux system to the currently logged in system.

Here's a generic syntax that copies the file from the home directory of the user on the remote system to the current directory of your locally logged in system.

scp username@ip_address:/home/username/filename .

Do you see the similarity with the cp command? It's almost the same except that you have to specify username and ip address with colon (:).

Now, let me show you a real-world example of this command.

How to Upload Files to Remote System Over SSH (2)

In the example above, I copied the file remote.txt from the /home/abhishek/my_file directory on the remote system to the current directory of the local machine.

This should give you a hint that you should know the exact location of the file on the remote system. The tab completion does not work on remote systems.

Copy files from your local machine to the remote machine

How to Upload Files to Remote System Over SSH (3)

The scenario is slightly changed here. In this one, you are sending a local file to the remote system over SSH using scp.

This is a generic syntax which will copy the filename to the home directory of username on the remote system.

scp filename username@ip_address:/home/username
How to Upload Files to Remote System Over SSH (4)

In the above example, I copied local.txt file from the current directory to the home directory of the user abhishek on the remote system.

Then I logged into the remote system to show that the file has actually been copied.

You can copy directories too

Remember I told you I like scp because of its similarity with the cp command?

Like cp command, you can also use scp to copy directory over SSH. The syntax is similar to the cp command too. You just have to use the -r option.

scp -r source_dir username@ip_address:/home/username/target_dir

You can do a lot more with it. Read some more examples of scp command in this tutorial:

Using scp Command in Linux: 10 Practical Examples ExplainedHere are some practical and essential scp command example to show how to securely copy files between remote Linux systems.Linux HandbookAbhishek Prakash

Method 2: Use rsync to copy files and directories over SSH

Since scp is being deprecated, rsync is the next best tool for copying files between remote system over SSH. Actually, it is better than scp in many terms.

The command syntax is the same as scp. Older versions of rsync had to use rsync -e ssh but that's not the case anymore.

Copy files from the remote machine to your local machine

Let's say you want to copy a file from the home directory of the user on the remote system to the current directory of your locally logged in system.

rsync username@ip_address:/home/username/filename .

Let's take the same example you saw with scp. I am copying the file remote.txt from the /home/abhishek/my_file directory on the remote system to the current directory of the local machine.

How to Upload Files to Remote System Over SSH (7)

Copy files from your local machine to the remote machine

Here is a generic syntax which will copy the file to the home directory of username on the remote system.

rsync filename username@ip_address:/home/username

Time to see the real world example. I am copying local.txt file from the current directory to the home directory of the user abhishek on the remote system.

How to Upload Files to Remote System Over SSH (8)

How about copying directories with rsync?

It's the same. Just use -r option with rsync to copy entire directory over SSH between remote systems.

rsync -r source_dir username@ip_address:/home/username/target_dir

Take a look at this example. I copy the entire my_file directory from the remote system to the local system.

How to Upload Files to Remote System Over SSH (9)

rsync is a versatile tool. It is essentially a tool for 'recursively syncing' the contents between two directories and quite popular for making automated backups.

15 Practical Examples of rsync Command in LinuxWondering how to use rsync command? This article lists some of the essential usages of the rsync command in Linux.Linux Handbookseeni

Method 3: Using SSHFS to access files from remote system over SSH

There is also SSHFS (SSH Filesystem) that can be used to access remote files and directories. However, this is not very convenient just for copying files.

In this method, you mount the remote directory on your local system. Once mounted, you can copy files between the mounted directory and the local system.

You may need to install sshfs on your local system first using your distribution's package manager.

On Debian and Ubuntu, you may use the following command:

sudo apt install sshfs

Once you have sshfs installed on your system, you can use it to mount the remote directory. It would be better to create a dedicated directory for the mount point.

mkdir mount_dir

Now mount the desired directory on the remote machine in this fashion:

sshfs username@IP_address:path_to_dir mount_dir

Once it is mounted, you can copy files into this directory or from this directory as if it is on your local machine itself.

cp local_file mount_dir

Remember that you have mounted this file. Once your work is done, you should also unmount it:

umount mount_dir

Here's an example where I mounted the my_file directory from the remote system to the remote_dir directory on the local system. I copied the remote.txt file to the local system and then unmounted the directory.

How to Upload Files to Remote System Over SSH (12)

Method 4: Use a GUI-based SFTP client for transferring files between remote systems

As the last resort, you can use an FTP client for transferring files between remote and local systems.

FileZilla is one of the most popular cross-platform FTP client. You can easily install on your local system.

Once installed, go to File->Site Manager and add the remote system details like IP address, SSH port number, username and password.

How to Upload Files to Remote System Over SSH (13)

Once you connect, you can see a split window view that shows the local filesystem on the left and the remote filesystem on the right.

How to Upload Files to Remote System Over SSH (14)

To transfer the file, drag and drop files from left to right or right to left. A progress bar appears at the bottom.

Which method do you prefer?

Alright! I showed various command line and GUI methods that can be used for copying files over SSH.

Now it is up to you to decide which method to use here. Do comment your preferred method for transferring files over SSH.

How to Upload Files to Remote System Over SSH (2024)
Top Articles
How Far Is a 10k? Plus, the Perfect Training Plan for You
How to Give Cryptocurrency As a Gift
What Is Single Sign-on (SSO)? Meaning and How It Works? | Fortinet
Duralast Gold Cv Axle
My Arkansas Copa
Obor Guide Osrs
Western Union Mexico Rate
Coffman Memorial Union | U of M Bookstores
Linkvertise Bypass 2023
Self-guided tour (for students) – Teaching & Learning Support
Nieuwe en jong gebruikte campers
Cape Cod | P Town beach
Ella Eats
Diablo 3 Metascore
Kris Carolla Obituary
Morgan And Nay Funeral Home Obituaries
Finger Lakes Ny Craigslist
Napa Autocare Locator
Trac Cbna
R Personalfinance
Swgoh Blind Characters
Evil Dead Rise - Everything You Need To Know
Indiana Wesleyan Transcripts
Leccion 4 Lesson Test
Promiseb Discontinued
C&T Wok Menu - Morrisville, NC Restaurant
Thick Ebony Trans
Bn9 Weather Radar
1145 Barnett Drive
Jackie Knust Wendel
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Hrconnect Kp Login
Angel Haynes Dropbox
Will there be a The Tower season 4? Latest news and speculation
Rs3 Bring Leela To The Tomb
Our 10 Best Selfcleaningcatlitterbox in the US - September 2024
Why comparing against exchange rates from Google is wrong
Otis Inmate Locator
Planned re-opening of Interchange welcomed - but questions still remain
The Posturepedic Difference | Sealy New Zealand
2487872771
+18886727547
Used 2 Seater Go Karts
Fridley Tsa Precheck
Usf Football Wiki
D-Day: Learn about the D-Day Invasion
Conroe Isd Sign In
Cranston Sewer Tax
Wilson Tattoo Shops
Owa Hilton Email
Acuity Eye Group - La Quinta Photos
Evil Dead Rise - Everything You Need To Know
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5591

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.