0% found this document useful (0 votes)
23 views

How To Transfer Files Over SSH With SSHFS in Linux Windows

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

How To Transfer Files Over SSH With SSHFS in Linux Windows

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

www.golinuxcloud.

com /how-to-transfer-files-over-ssh-with-sshfs/

How to transfer files over SSH with SSHFS in Linux &


Windows
⋮ 5/17/2020

There are various tools available to copy files and directories between Linux server. In this article we will use
SSHFS to transfer files over SSH from local to remote and remote to local server.

You can also use below tools to copy files between Linux servers:

Overview on SSHFS
SSHFS (Secure SHell FileSystem) is a file system for Linux (and other operating systems with a FUSE
implementation, such as Mac OS X or FreeBSD) capable of operating on files on a remote computer
using just a secure shell login on the remote computer.
The sshfs command is a client tool for using SSHFS to mount a remote file system from another server
locally on your machine.
SSHFS allows you to mount a remote directory from remote server on your local machine using a mount
point, and have it treated just like any other directory.

Advantage of using SSHFS


Compared to other shared filesystem such as NFS and Samba we do not need any server or client side
configuration
SSHFS is a simple client tool which does not requires any additional configuration
You can also use SSHFS to transfer files over SSH between Linux and Windows Server
The files are transferred in completely encrypted channel so it is very secure

Drawbacks of using SSHFS


You mount the remote directory on local server similar as NFS server but with transfer over SSH using
SSHFS both encryption and decryption is involved which can cause performance impacts
You should also save your data on the mount point as if there is a network connection problem then you
may loose your data

ALSO READ
Learn Linux wheel group usage [With Examples]

Transfer File over SSH between two Linux servers


Install SSHFS on Linux

SSHFS is an opensource project and is not available in most default repositories of distributions

To install SSHFS on RHEL/CentOS 7, we must first install EPEL repository

bash

# yum -y install epel-release

HINT:
At the time of writing this article, SSHFS was not available for RHEL/CentOS 8

Next install sshfs on your client node

bash

[root@server1 ~]# yum -y install sshfs

To install sshfs on Ubuntu and Debian

bash

$ sudo apt install sshfs

1/6
Mount Remote File System

To transfer files over SSH using SSHFS, we must execute SSHFS using below syntax:

bash

sshfs [user@]host:[dir] mountpoint [options]

Check sshfs -h to get the complete list of supported options

In this example I have installed SSHFS on server1 and we will mount

Remote directory (/shared) from server2

bash

[root@server2 ~]# ls -l /shared/


total 0
-rw-r--r-- 1 root root 0 May 17 19:21 file1
-rw-r--r-- 1 root root 0 May 17 19:21 file2
-rw-r--r-- 1 root root 0 May 17 19:21 file3

to my local Linux node on server1 at (/mount_point)

bash

[root@server1 ~]# ls -l /mount_point/


total 0

So we must execute sshfs on server1, we are using root user to transfer files over SSH. You can use any
normal user, but make sure this user has enough permission to access the remote directory on server2

bash

[root@server1 ~]# sshfs root@192.168.43.10:/shared /mount_point


root@192.168.43.10's password:

There was no error reported so the mount was successful. Verify the mount point on server1

bash

[root@server1 ~]# mount | grep shared


root@192.168.43.10:/shared on /mount_point type fuse.sshfs
(rw,nosuid,nodev,relatime,user_id=0,group_id=0)

You can now access the content of remote directory (/shared) from server2 on /mount_point directory
on local Linux node at server1

bash

[root@server1 ~]# ls -l /mount_point/


total 0
-rw-r--r--. 1 root root 0 May 17 19:21 file1
-rw-r--r--. 1 root root 0 May 17 19:21 file2
-rw-r--r--. 1 root root 0 May 17 19:21 file3

Now we can add and modify content under /mount_point at server1 and the changes will be reflected
runtime on server2 at /shared

Snippet from my terminal

Transfer files over SSH in Linux

2/6
ALSO READ
5 simple methods to test ssh connection in Linux & Unix

To permanently mount this remote directory use /etc/fstab using below syntax:

bash

user@host:/remote/path /local/mount_point fuse.sshfs defaults 0 0

In this example we will add below content in our /etc/fstab

bash

root@192.168.43.10:/shared /mount_point fuse.sshfs defaults 0 0

Un-mount Remote File System

Once you have transferred your files, you can also un-mount the remote file system using umount. Execute
umount on server1:

bash

[root@server1 ~]# umount /mount_point/

Verify and make sure there are no mount paths using /shared directory from remote server i.e. server2

bash

[root@server1 ~]# mount | grep shared

Transfer File over SSH between Windows and Linux servers


You can also use SSHFS to transfer files over SSH between Windows and Linux server.
This can also be achieved using Samba but let us concentrate on SSHFS for the sake of this article

Install SSHFS on Windows

To transfer files over SSH between Windows and Linux, you must install SSHFS on the WIndows server.
You can get the files required to installed from the official Github page
Download WinFsp and follow the onscreen instructions to install WinFsp on your Windows server
Download SSHFS-Win and follow the onscreen instructions to install SSHFS-Win on your Windows
server
At the time of writing this article I have installed winfsp-1.6.20027.msi and sshfs-win-
3.5.20024-x64.msi

Mount Remote File System

Once you have installed WinFsp and SSHFS-Win on your windows server, next we must map the network
location from remote server to a local mount point

I am using WIndows 10 so I will share the instructions based on my environment.

In Windows Explorer select This PC ⇒ Map Network Drive

Map network Drive

ALSO READ
Steps to repair filesystem in rescue mode in RHEL/CentOS 7/8 Linux

Provide the path of your remote server and remote directory using the below syntax

bash

3/6
\\sshfs\REMUSER@HOST[\PATH]

NOTE:
Here we cannot directly give our mount point as /shared from our remote Linux server. We must use (/) to navigate around the
Linux server. In this example we will connect to the home folder of our root user using
bash

\\sshfs\root@192.168.43.10\

Mount remote file system

Provide the login credentials for root user from the remote server i.e. server2

login credential

If all is good, you will be connected to your remote Linux server using Windows server. You can verify the path
in the Navigation Pane. By default we are connected to home folder of root user

Transfer files over SSH between Windows and Linux

How to connect to different folder using SSHFS in Windows?

In Windows SSHFS we are by default connected to user's home directory so we must provide the absolute path
using navigation symbols i.e. to go to /shared directory our path to transfer files over SSH on Windows
would be //sshfs/root@192.168.43.10/../shared

If you NOTICE, I have first changed my current directory using ../ followed by the path of /shared
directory. I hope you understand the point.

4/6
Provide different remote directory path

Now we are connected to /shared directory where we had created three dummy files on server2

Transfer files over SSH between Linux and Windows

For list of Advanced Usage with Windows SSHFS, check the official Github page for instructions

Disconnect Remote File System

Once you are done, to disconnect the network drive, in Windows Explorer select This PC. Look out for
your mapped drive and Right Click on the drive to get a list of options. Select Disconnect to remove the
mapped drive from your Windows server.

ALSO READ
PSSH - 10 practical examples to use parallel SSH in Linux

Disconnect mapped drive from Windows

Conclusion
Lastly I hope the steps from the article to configure NIC teaming on Linux was helpful. In this tutorial we
learned about SSHFS and how we can use SSHFS to transfer files over SSH between two Linux servers or
between Linux and Windows server. So, let me know your suggestions and feedback using the comment
section.

5/6
6/6

You might also like