[SOLVED] Automount fs over ssh using autofs and sshfs (with fuse)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Automount fs over ssh using autofs and sshfs (with fuse)
I've just found out how effective autofs is, especially with mounting and unmounting network file systems.
I am attempting to have autofs automount a directory from a server configured to use openssh. I do not have any power over the server other than reading and writing my files.
I have setup auto.master to include the following line:
I can use sshfs just fine on the command line and it mounts for both my $user and root. The issue is when accessing myServer under netfs/ssh/, the system hangs then cd prints out
Code:
cd: no such file or directory: myServer
I believe 'cd' reacts like so since the dirctory is a ghost (just a trigger to autofs); only succeeding when mounting is done.
How am I able to automount this directory via autofs without this issue?
The usual problem is getting proper access to the keys for ssh. Root is the one doing the mount, not the user; So I would expect some issues with identifying the correct keys for use.
I thought that was the problem since, as you just mentioned, root was the one actually doing the mount.
However, I have authorised both my username and root for passwordless authentication.
Root also has the server on the list of known hosts.
I attempted to mount my directory using sshfs as root and it mounted without issues.
I just wished to automate this with autofs.
I thought that was the problem since, as you just mentioned, root was the one actually doing the mount.
However, I have authorised both my username and root for passwordless authentication.
Root also has the server on the list of known hosts.
I attempted to mount my directory using sshfs as root and it mounted without issues.
I just wished to automate this with autofs.
Depending on distribution, the credentials used are identified by the login identity - not the uid. The root process doing the autofs has / for a home directory (sometimes it may be /etc or even /tmp), not /root, thus trying to access the credentials could fail.
So is there a way to direct the root process to the credentials to use?
Something I would probably include in the list of options for autofs or the underlying sshfs.
Better yet is there a log file where I can look into the connection process and get a better look on what's really going on?
The other problem with autofs is that it will try to dismount the filesystem using umount... which isn't a "fusermount -u"
There may actually be a way - but most of the references I find for using autofs and sshfs are old (2012 was the most recent, but https://wiki.archlinux.org/index.php/autofs for Arch has a posting only a couple of months old.
I tried adding the option 'IdentityFile=/home/username/.ssh/id_rsa' ofcourse applying it to my case (username).
Though it still hangs for about 10 sec then fails.
These are both valid options.
Though I wish the original issue to be solved.
For the mean time, I will keep this thread open to give opportunity for other suggestions.
May not make a difference but you might have two syntax errors i.e.
fstype=fuse... should be -fstype=fuse...
And you did not specify a directory on the server i.e.
:sshfs\#user@host\: should be :sshfs\#user@host\:/path/to/directory
You can debug autofs by using the automount command. Shutdown autofs then run the command in another terminal
automount -f --debug (once started ctrl-c is required to shutdown automount)
Now go back and try to cd to your myserver directory. Look at the debug messages to see where autofs errors. ssh is particular on the id_rsa permissions. When you ssh via the command line as root are you using your user or roots id_rsa key? Are you using the standard (22) or non standard port?
add_host_addrs: hostname lookup failed: Name or service not known
mount(nfs): no hosts available
dev_ioctl_send_fail: token = 3
failed to mount /netfs/ssh/myServer
PS.
When mounting as root I used the root's id_rsa key under /root.
I tried using
Code:
IdentityFile=/root/.ssh/id_rsa
though the outcome did not change.
and yes I use the standard port 22.
If you happen to be using a NetworkManager for initialization you likely have to enable "NetworkManager-wait-online" to force systemd to wait until the network is actually up.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.