LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-12-2016, 01:27 PM   #1
AnsemEco
LQ Newbie
 
Registered: Jul 2016
Distribution: Arch linux
Posts: 25

Rep: Reputation: Disabled
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:

Code:
/netfs/ssh /etc/autofs/auto.ssh --timeout=60,--ghost
and auto.ssh to include the following:

Code:
myServer    fstype=fuse,rw,uid=1000,gid=1000,allow_other :sshfs\#user@host\:
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?
 
Old 08-13-2016, 07:13 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
Old 08-13-2016, 07:24 AM   #3
AnsemEco
LQ Newbie
 
Registered: Jul 2016
Distribution: Arch linux
Posts: 25

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-13-2016, 08:37 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by AnsemEco View Post
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.
 
Old 08-13-2016, 08:44 AM   #5
AnsemEco
LQ Newbie
 
Registered: Jul 2016
Distribution: Arch linux
Posts: 25

Original Poster
Rep: Reputation: Disabled
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?

Last edited by AnsemEco; 08-13-2016 at 08:50 AM.
 
Old 08-13-2016, 09:08 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Not that I know of.

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.
 
Old 08-13-2016, 10:40 AM   #7
AnsemEco
LQ Newbie
 
Registered: Jul 2016
Distribution: Arch linux
Posts: 25

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-13-2016, 10:56 AM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
For convenience, you can always set an alias and skip autofs

Code:
alias cdnetfs="sshfs user@host:/remote/dir /netfs/ssh && cd /netfs/ssh"
 
Old 08-13-2016, 01:08 PM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by keefaz View Post
For convenience, you can always set an alias and skip autofs

Code:
alias cdnetfs="sshfs user@host:/remote/dir /netfs/ssh && cd /netfs/ssh"
Or make script for an auto start login that does the mount. Might have to experiment with getting it dismounted though.
 
Old 08-13-2016, 02:39 PM   #10
AnsemEco
LQ Newbie
 
Registered: Jul 2016
Distribution: Arch linux
Posts: 25

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-13-2016, 04:28 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
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?
 
1 members found this post helpful.
Old 08-13-2016, 06:09 PM   #12
AnsemEco
LQ Newbie
 
Registered: Jul 2016
Distribution: Arch linux
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thanks to michaelk, I think I have a lead.

Code:
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.
 
Old 08-13-2016, 07:05 PM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Are you using ip address in the auto.ssh file?
 
Old 08-13-2016, 09:41 PM   #14
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
Old 08-13-2016, 09:59 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Not necessarily, since autofs is "on demand" the network should already be up.
 
  


Reply

Tags
autofs, sshfs



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sshfs-fuse: /usr/bin/ld: cannot find -lfuse Lennie Linux From Scratch 2 07-20-2013 02:59 PM
sshfs without fuse? stateless Linux - Newbie 1 01-30-2013 02:44 PM
how can i install sshfs and fuse rpm in centos jsaravana87 Linux - Newbie 3 10-22-2011 07:32 AM
How to keep alive (or reconnect) fuse SSHFS mount between sleep/hibernate? lefty.crupps Linux - Desktop 4 11-16-2010 09:17 PM
shared filesystem crap: shfs, sshfs, lufs, fuse whansard Linux - Networking 1 06-26-2005 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration