How to mount a remote directory in Linux using sshfs

Q. I have access rights to one of the remote server through SSH protocol and there is no File share services such as Samba, NFS or FTP etc which are enabled on the server. Now I want to mount data from that remote server, is it possible to mount remote folders?

A. The answer to this is yes, We can share data/mount folder on a local machine by using just SSH protocol. This can be done by using FUSE(Filesystem in USErspace) whichsupport SSH and FTP file systems. This post is in response to conversation which I had with one our users two days back. the question he asked about ftp is “I want to transfer one latest file from my ftp server and I want to automate this task through shell script to download latest file from my FTP server, And I don’t know what is the Operating System at server end(This is ultimate sentence I hear from the user today in my office  )“. Let’s prepare our machine on how to mount a remote folder by using SSH protocol.

Step1: Installing Package

On Ubuntu/Debain

apt-get install sshfs

On Redhat/CentOS/Fedora

rpm -ivh fuse-sshfs-1.8-1.el5.rf.i386.rpm

Step2: Once the package is installed we have to create a mount point and mount our  server data using sshfs command, for which we require  username/password. Here are my details for this task.

My Username: root

My password: redhat

My Server: 10.233.10.212

My mount point: /mnt/ssh

Now create the mount point and mount SSH account data.

#mkdir /mnt/ssh

#sshfs [email protected]:/ /mnt/ssh/

[email protected]‘s password:

Step3: The above command will mount my root directory in 10.233.10.212 server. Testing our setup

Check if you are able to see data

#cd /mnt/ssh

#ls

Sample output

bin   cdrom     data  etc   initrd.img      lib         media  opt   root  selinux  sys   tmp  var      vmlinuz.old
boot  cmdb-bkp  dev   home  initrd.img.old  lost+found  mnt    proc  sbin  srv      test  usr  vmlinuz

What about df -hs command output?

Sample output

Filesystem Size Used Avail Use% Mounted on
/dev/sda2 12G 8.4G 2.5G 78% /
/dev/sda6 80G 43G 34G 56% /var
/dev/sda5 2.0G 41M 1.8G 3% /home
/dev/sda1 99M 12M 83M 12% /boot
tmpfs 506M 0 506M 0% /dev/shm
sshfs#[email protected]:/ 1000G 0 1000G 0% /mnt/ssh

Step4: So what about mounting it permanently?. We can do it by editing fstab file in /etc folder

#vi /etc/fstab

go to last line and type below line

sshfs#[email protected]:/ /mnt/ssh fuse defaults 0 0

Save the file and exit. Now run mount -a to update the fstab file state to kernel.

Note: Its not advisable to write passwords in human readable files like /etc/fstab.

#mount -a

Let me explain what entry in fstab indicates. We are mentioning mount user root data which is located on 10.233.10.212 server on to /mnt/ssh using fuse file system with default settings.

Step5: What about unmounting this drive?

#umount /mnt/ssh

Enjoy new learning of mounting a folder using SSH protocol.

时间: 2024-07-31 20:50:24

How to mount a remote directory in Linux using sshfs的相关文章

Using sshfs to mount remote directory

*/--> Using sshfs to mount remote directory I am working on different locations, but I do not want to copy all the files from one computer to another, the simplest way to avoid the trouble of duplicating files are using sshfs. In order to make sshfs

【Linux基础】mount报错:mount.nfs: Remote I/O error

mount 报错:mount.nfs: Remote I/O error 挂载时需要指明版本,由于NFS服务器有多个版本,V2.V3.V4.而且各版本同时运行,因此挂载时需要说明版本号. 由于NFS V2最大只支持32BIT的文件大小(4g),而NFS V3则支持64BIT文件大小.另外V3对于V2还有其他优势,比如文件传输,异步写入等,因此建议采用V3进行访问. 解决办法:mount 加选项 -o nfsvers=3或者-o nfsvers=2       后面IP:/.../..   /..

How to Mount a Remote Folder using SSH on Ubuntu

Connecting to a server across the internet is much more secure using SSH. There is a way that you can mount a folder on a remove server using the SSHFS service. There are quite a few steps that you’ll have to follow, so get ready and open a terminal

Linux安装sshfs挂载远程目录到本地及卸载

挂载远程目录的方式很多,这里把sshfs记录一下备忘.Linux用sshfs挂载远程目录到本地 安装sshfs 在Ubuntu下,只需要使用 $ sudo apt-get install sshfs 一共才140kB 挂载远程目录到本地 $ sshfs [email protected]:path MountDir 例如 $ sshfs [email protected]:/home/Suzzz ~/Tmp/ 这样就把远程目录 /home/Suzzz挂载到了本地的 ~/Tmp下 这样的挂载,在文

Mount Windows (CIFS) shares on Linux with credentials in a secure way

  Posted on 09/09/2014 In almost all cases, when mounting a CIFS-share on a Linux host, you will need to supply some credentials. Either you could enter the credentials by hand every time you need the share or add the credentials to /etc/fstab to aut

使用VS Code配合Remote Development插件连接远程服务器(Mac/Linux+Windows) | Using VS Code with Remote Development Connect to Remote Server (Mac/Linux+Windows)

最新版VS Code(2019年6月)出了一系列新的插件,包括Remote Development,Remote SSH等,使得用户可以使用VS Code远程连接服务器写代码,方便了协同工作.具体配置(Mac/Linux, Windows)操作如下: 1.首先,在插件市场中搜索这些插件,安装Remote Development即可将一系列插件,包括Remote SSH等一同安装. 2.接下来需要生成ssh的key. 打开命令行,输入: ssh-keygen -t rsa -b 4096 接下来,

Linux使用sshfs挂载远程目录到本地

挂载远程目录的方式很多,这里把sshfs记录一下备忘. 安装 sshfs 在Ubuntu下,只需要使用 $ sudo apt-get install sshfs 一共才140kB 挂载远程目录到本地 $ sshfs  [email protected]:path  MountDir 例如 $ sshfs  [email protected]:/home/Suzzz     ~/Tmp/ 这样就把远程目录 /home/Suzzz挂载到了本地的 ~/Tmp下 这样的挂载,在文件管理器中也是可见的. 

remote mounting from windows to linux

8 Ways To Mount SMBfs (SAMBA FILE SYSTEM) In Linux. Sep 8, 2009 How to Mount smbfs (SAMBA file system) permanently in Linux.In this post I am going to give some examples how to do SMB (Server Message Block) mounts.. Type1 : Listing SMB shared folder

Linux添加硬盘 挂载硬盘(附 Linux磁盘挂载和mount共享 带图)

Linux添加硬盘 在为主机添加硬盘前,首先要了解Linux系统下对硬盘和分区的命名方法. 在Linux下对IDE的设备是以hd命名的,第一个ide设备是hda,第二个是hdb.依此类推 一般主板上有两个IDE接口,一共可以安装四个IDE设备.主IDE上的两个设备分别对应hda和hdb,第二个IDE口上的两个设备对应hdc和hdd. 一般硬盘安装在主IDE的主接口上,所以是hda 光驱一般安装在第二个IDE的主接口上,所以是hdc(应为hdb是用来命名主IDE上的从接口) SCSI接口设备是用s