Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Problems mounting remote directory using SSHFS

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
jaytelford
Posts: 36
Joined: 2018-05-09 10:56
Location: United KIngdom

Problems mounting remote directory using SSHFS

#1 Post by jaytelford »

Hi,

I have both a remote and local machine running Debian. The remote is running Debian GNU/Linux 8 and the local machine is running Debian GNU/Linux 9. I have been trying to mount my remote home directory in my local machine using SSHFS.

So far, here is what I have done:

GENERATED A KEY-PAIR TO LOGIN WITH SSH

1. Logged in as jaytelford I ran: ssh-keygen
2. When I was asked to enter a password, I hit enter and left it blank and then enter again to confirm

UPLOADED THE PUBLIC KEY CREATED IN THE PREVIOUS STEP TO THE REMOTE LOCATION
Note: I have replaced my actual remote locations IP address with 0.0.0.0 but during upload I used the correct one.

1. Uploaded the public key to the servers jaytelford account authorized key file via Terminal using:

Code: Select all

ssh-copy-id -i /home/jaytelford/.ssh/id_rsa.pub jaytelford@0.0.0.0
2. Tested the key by making an ssh connection to the remote from the local machine by entering this into Terminal:

Code: Select all

ssh -i /home/jaytelford/.ssh/id_rsa  jaytelford@0.0.0.0
I was then logged into the remote location without needing a password

3. Made sure I was being logged into the correct directory on the remote by issuing the ls command.

SET UP SSHFS ON THE LOCAL MACHINE

1. While logged in as root, I entered this into Terminal to install SSHFS on the local machine

Code: Select all

apt-get install sshfs
2. As the local user (not root) I created the server directory that I wanted to use as the mount point for the remote by putting this into Terminal

Code: Select all

mkdir /home/jaytelford/server
3. I then mounted the remote directory from the local machine by entering into Terminal:

Code: Select all

sshfs jaytelford@0.0.0.0:/home/jaytelford /home/jaytelford/server
Everything worked as expected and I was able to mount the remote location on the local machine, using the local server directory as the mount point. I could then interact with, created, edit and deleted files and directories on the remote from the local mount point. At this point though, I was having to manually mount the remote and I wanted the remote to be automatically mounted when the system booted up or woke up from sleep and so the next steps, are the steps I have taken in that regard.

EDITING THE FSTAB SO THAT THE REMOTE IS MOUNTED AT BOOT OR WAKEUP

1. I backed up the original fstab into the root directory by entering this into my Terminal while logged in as jaytelford.

Code: Select all

sudo cp /etc/fstab /root/fstab.bak
I was asked for my sudo password, which I entered and the operation completed successfully

2. I then made the mount persistent by opening the fstab in vim (using sudo), moving to the bottom of the file an entering this on a single line

Code: Select all

sshfs#jaytelford@0.0.0.0:/home/jaytelford /home/jaytelford/server fuse defaults,allow_other,delay_connect,IdentityFile=/home/jaytelford/.ssh/id_rsa 0 0
Despite how that code block looks here, I did actually enter it all onto one single line at the bottom of the fstab. I then saved the fstab and rebooted the system

PROBLEMS I AM HAVING AFTER MAKING THE MOUNT PERSISTENT

After making the mount persistent by editing the fstab as described above and rebooting the system, i came across an unexpected error. Although the remote is indeed mounted when the system boots, I can not access it either in Terminal or in the graphical files app.

When I try to cd into the server directory in Terminal (the directory I am using for the remote mount point) I get Read/Write error. If I try to access the server directory from within the graphical files app, I get an error that says "unknown file" and there is an option to choose which app I want to use to open the file. Choosing either Files or Terminal fails with these exact same errors.

Doing an ls in Terminal tells me that the server directory can not be listed

I can not unmount the remote either. Either from Terminal or the Files app. If I try, I get the same errors as described above.

The only way I was able to access the remote mount point, was to restore the fstab from backup, reboot the system and mount the remote manually, as described above during my set up and testing. Mounting manually works fine and also as described above, I have full access to the remote via the mount point if I mount the remote manually. Editing the fstab to mount the remote at boot however, always seems to succeed, but then I cant access the mount point, once I am actually logged into my user local user account.

Have I done something wrong in the setup or misunderstood the steps I needed to take to get this work?

User avatar
llivv
Posts: 5340
Joined: 2007-02-14 18:10
Location: cold storage

Re: Problems mounting remote directory using SSHFS

#2 Post by llivv »

Not knowing myself how sshfs and fuse work in Debain,
the first places I would start would be checking the kernel log and /proc/self/mountinfo
both with and without presistence added.
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.

reinob
Posts: 1195
Joined: 2014-06-30 11:42
Has thanked: 99 times
Been thanked: 47 times

Re: Problems mounting remote directory using SSHFS

#3 Post by reinob »

jaytelford wrote: ...

2. I then made the mount persistent by opening the fstab in vim (using sudo), moving to the bottom of the file an entering this on a single line

Code: Select all

sshfs#jaytelford@0.0.0.0:/home/jaytelford /home/jaytelford/server fuse defaults,allow_other,delay_connect,IdentityFile=/home/jaytelford/.ssh/id_rsa 0 0
...
The fstab mounts are done as root, so it will not be 1-to-1 what you experienced when mounting it manually as your user.
The allow_other option is OK as it allows users to access the mount point.
But still the permissions (effective user/group id owning the mounted files) may not be what you want/need.
You could, from the command line, post the output of "ls -al /home/jaytelford/server", to check if something is not right with the permissions.

You may want to have a look here: https://wiki.archlinux.org/index.php/SSHFS
and specfically the section "Secure user access", i.e. the options default_permissions, uid and gid.

Ynot
Posts: 16
Joined: 2019-01-11 18:39

Re: Problems mounting remote directory using SSHFS

#4 Post by Ynot »

jaytelford wrote:...
2. I then made the mount persistent by opening the fstab in vim (using sudo), moving to the bottom of the file an entering this on a single line

Code: Select all

sshfs#jaytelford@0.0.0.0:/home/jaytelford /home/jaytelford/server fuse defaults,allow_other,delay_connect,IdentityFile=/home/jaytelford/.ssh/id_rsa 0 0
...
One reasonably suspects that the "#" in sshfs#jaytelford... is being treated as a comment. Have you tried enclosing the fs_spec field in quotes in order to deal with the space that the command-line invocation contains, instead of using "#"?

Another suggestion is instead of using fstab, create an executable file /etc/rc.local that contains:

Code: Select all

#!/usr/bin/env bash
/usr/bin/sshfs jaytelford@0.0.0.0:/home/jaytelford /home/jaytelford/server -o IdentityFile=/home/jaytelford/.ssh/id_rsa
exit 0
... assuming that the -o option is correct. Be sure to make /etc/rc.local executable before testing with "systemctl restart rc-local". If you want to experiment with the -o options (such as to change user or group ID to match yours on the mounted filesystem; default uid=gid=0) then be sure to restart it again. It will always be invoked when the system comes up.

jaytelford
Posts: 36
Joined: 2018-05-09 10:56
Location: United KIngdom

Re: Problems mounting remote directory using SSHFS

#5 Post by jaytelford »

Humm, that would be a workaround to the fstab issue and having to mount manually.

xepan
Posts: 89
Joined: 2018-11-28 06:38

Re: Problems mounting remote directory using SSHFS

#6 Post by xepan »

never did it via fstab, but i got two results which mention that the _netdev option is needed for it:

Code: Select all

user@host:/remote/folder /mount/point  fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/user/.ssh/id_rsa,allow_other,reconnect 0 0
https://wiki.archlinux.org/index.php/SSHFS

unrelated side note: the : is a shortcut for the users home; hence in user@remote:/home/user /home/user is superfluous.

User avatar
llivv
Posts: 5340
Joined: 2007-02-14 18:10
Location: cold storage

Re: Problems mounting remote directory using SSHFS

#7 Post by llivv »

jaytelford wrote:PROBLEMS I AM HAVING AFTER MAKING THE MOUNT PERSISTENT

After making the mount persistent by editing the fstab as described above and rebooting the system, i came across an unexpected error. Although the remote is indeed mounted when the system boots, I can not access it either in Terminal or in the graphical files app.

When I try to cd into the server directory in Terminal (the directory I am using for the remote mount point) I get Read/Write error. If I try to access the server directory from within the graphical files app, I get an error that says "unknown file" and there is an option to choose which app I want to use to open the file. Choosing either Files or Terminal fails with these exact same errors.

Doing an ls in Terminal tells me that the server directory can not be listed

I can not unmount the remote either. Either from Terminal or the Files app. If I try, I get the same errors as described above.

The only way I was able to access the remote mount point, was to restore the fstab from backup, reboot the system and mount the remote manually, as described above during my set up and testing. Mounting manually works fine and also as described above, I have full access to the remote via the mount point if I mount the remote manually. Editing the fstab to mount the remote at boot however, always seems to succeed, but then I cant access the mount point, once I am actually logged into my user local user account.
just noticed
https://wiki.debian.org/systemd#SSH_ses ... 2Fshutdown
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.

User avatar
llivv
Posts: 5340
Joined: 2007-02-14 18:10
Location: cold storage

Re: Problems mounting remote directory using SSHFS

#8 Post by llivv »

just found this and since it is current I thought it deserved it's own post instead of an edit to the previous post.
https://daniel-lange.com/archives/152-O ... mness.html

best of luck and I hope you find a solution...

I just got another idea if you want to look into concerning versioning.
(thinking bare meatal becasue that is how I work, but could possibly apply to vm as well)
If you can setup a Dual boot Stretch with a new Buster install on the remote and see if the same results show up?
In memory of Ian Ashley Murdock (1973 - 2015) founder of the Debian project.

Post Reply