Why auto mounting sshfs using autofs fails?
Short:
Check that your sshfs command works with root user.
Longer:
Check that root user has ssh identity keys setup. Mounting of sshfs through autofs uses root user for the actual mount.
This is still meant only for desktop or laptop users with a single user using these mounts!
auto.master line
note! use your own uid and gid and specify your prefered mount point I use /auto/mehtod/address
/auto/sshfs /etc/auto.sshfs uid=1000,gid=1000,--timeout=60,--ghost
auto.sshfs this is a bit more generic than just one mount
#!/bin/bash
# Shell script that acccepts one argument, namely userid@server
# env >> /tmp/env_check
# whoami >> /tmp/env_check
key=$1
USER='your_local_user_used_for_ssh_identity_file'
REMOTEDEFAULT='default_to_this_user_otherwise_root'
key=${key//[: #]/}
# add user
[[ ! "$key" =~ "@" ]] && key="${REMOTEDEFAULT}@${key}"
case $key in
${REMOTEDEFAULT}@.Trash*)
exit 1;;
*)
(
echo "-fstype=fuse,idmap=user,rw,nodev,nonempty,transform_symlinks,noatime,allow_other,IdentityFile=/home/${USER}/.ssh/id_dsa,max_read=65536\\"
echo -e "\t /uhome :sshfs\#$key\:\\"
echo -e "\t /tmp :sshfs\#$key\:\/tmp\/\\"
echo -e "\t /rootfs :sshfs\#$key\:\/")
esac
## this is a bit more complex. It creates subfolders to autofs-mount/remotename
## /uhome = your remote homedirectory
## /rootfs = remote root '/'
## /tmp = remote tmp # same as /roots/tmp
then link to folder you want to access ln -s /auto/sshfs/[email protected]/uhome/ remote-home
Related videos on Youtube
Cyril N.
Updated on September 18, 2022Comments
-
Cyril N. over 1 year
I'm desperetely trying to auto mount my distant folder using autofs & sshfs, but I can't make it work. (I'm under Fedora 16)
This works :
sshfs [email protected]:/my/data /home/cx42net/data-distant -o uid=1000 -o gid=1000
So I defined a RSA key to use with ssh, tried a
ssh
connect, it worked without asking my password. Then I tried again the previoussshfs
command, and it worked well (yay!)So now, I want to use
autofs
, and that's where the problem starts :Content of my /etc/auto.master file :
# # Sample auto.master file # This is an automounter map and it has the following format # key [ -mount-options-separated-by-comma ] location # For details of the format look at autofs(5). # /misc /etc/auto.misc # # NOTE: mounts done from a hosts map will be mounted with the # "nosuid" and "nodev" options unless the "suid" and "dev" # options are explicitly given. # /net -hosts # # Include /etc/auto.master.d/*.autofs # +dir:/etc/auto.master.d # # Include central master map if it can be found using # nsswitch sources. # # Note that if there are entries for /net or /misc (as # above) in the included master map any keys that are the # same will not be seen as the first read key seen takes # precedence. # +auto.master /net /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost
(1000:1000) is my local user uid/gid, not the distant (the SSH folder I'm trying to get)
My /etc/auto.sshfs :
data-distant -fstype=fuse,port=22,rw,allow_other :sshfs\#[email protected]\:/mnt/data/dev
When I start autofs, here's what I've got in the
/var/log/messages
:Oct 28 23:59:30 pc-maison autofs[3318]: Starting automount: [ OK ]
So everything seems fine.
But I sometimes got this kind of messages:
Oct 28 23:41:01 pc-maison automount[2453]: create_udp_client: hostname lookup failed: Name or service not known Oct 28 23:41:01 pc-maison automount[2453]: create_tcp_client: hostname lookup failed: Name or service not known Oct 28 23:41:01 pc-maison automount[2453]: lookup_mount: exports lookup failed for data-distant
The folder
/net/data-distant
have rights of my user "cx42net" (1000:1000)What am I missing to make this works ?