Sshfs als Benutzer über autofs ausführen

2792
billyjmc

Meine Situation:

  • In meinem LAN gibt es mehrere Server, die ich nicht verwalte
  • Ich greife mit SSH auf SSHFs, Shells und Remote-X11-Apps zu
  • Ich habe ControlMaster autoin meiner ~/.ssh/configDatei festgelegt, so dass keine Authentifizierungsverzögerung auftritt
  • Ich benutze Kompression und schnelle / schwache Verschlüsselungen, da ich entweder in einem privaten LAN oder VPN bin
  • Wo immer möglich, habe ich meinen (passwortlosen) öffentlichen RSA-Schlüssel auf die Server exportiert

Ich habe angefangen, autofs zu verwenden, um mir das Leben zu erleichtern, aber autofs möchte alle Mount-Befehle als root ausführen. Ich kann natürlich ein neues RSA-Schlüsselpaar als Root generieren und exportieren, und meine eigenen ~/.ssh/configOptionen auch in die Konfigurationsdatei des Superbenutzers replizieren, aber ich möchte lieber nicht zwei Kopien dieser Dinge aufbewahren, und dies löst meinen Wunsch nicht um nur eine offene SSH-Verbindung zu jedem Host zu haben. Daher möchte ich haben autofs laufen sshfsals nicht privilegierter Benutzer, genau wie es funktioniert, wenn sie manuell am Terminal aufgerufen.

Ich habe mir Autofs- Skripte angesehen, aber diese scheinen keine Lösung für mein Problem zu sein. Irgendwelche Vorschläge?

4

4 Antworten auf die Frage

3
billyjmc

Taken directly from the afuse homepage (emphasis mine):

afuse is an automounting file system implemented in user-space using FUSE. afuse currently implements the most basic functionality that can be expected by an automounter; that is it manages a directory of virtual directories. If one of these virtual directories is accessed and is not already automounted, afuse will attempt to mount a filesystem onto that directory. If the mount succeeds the requested access proceeds as normal, otherwise it will fail with an error. See the example below for a specific usage scenario.

The advantage of using afuse over traditional automounters is afuse runs entirely in user-space by individual users. Thus it can take advantage of the invoking users environment, for example allowing access to an ssh-agent for password-less sshfs mounts, or allowing access to a graphical environment to get user input to complete a mount such as asking for a password.

This option seems like a shoo-in.

1
kreator

JFTR, I've modified (and simplified) ssh_user so that it first tries to contact the user's ssh-agent:

#!/bin/bash # Open a ssh connection as a given user, thus using his/hers authentication # agent and/or config files. : $ : $ export SSH_AUTH_SOCK=$(find /tmp/ssh-* -type s -user $ -name agent* | tail -1) declare -a options=( $* ) # Remove unwanted options for (( i=0,fin=${#options[*]} ; i < fin ; i++ )) do case $ in (-a|-oClearAllForwardings=*) unset options[$i] ;; esac done exec /bin/su $ -c "$(which ssh) $ $" 
1
kynan

autosshfs könnte dem, was Sie suchen, nahekommen: Es handelt sich um "pro Benutzer SSHFS-Automount unter Verwendung der SSH-Konfiguration und -schlüssel des Benutzers".

Ich mag das. Das Problem, das ich habe, ist, dass nicht alle meine Remote-Hosts mir erlauben, öffentliche / private Schlüsselpaare für die Anmeldung zu verwenden (ja, das ist scheiße und macht keinen Sinn). billyjmc vor 10 Jahren 0
0
billyjmc

Drawing heavily from another similar question, I've found a solution. It required some serious experimentation and tweaking, though. Note that this modified script is now incompatible with mounting from /etc/fstab.

/etc/auto.master

/- /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost 


/etc/auto.sshfs

/local/mountpoint -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,workaround=rename,ssh_command=/usr/local/sbin/ssh_user :sshfs\#remoteuser@server\:/remote/path 


This needs to be executable, of course: /usr/local/sbin/ssh_user

#!/bin/bash # declare arrays for ssh options declare -a ADD_OPTIONS declare -a CLEANED_SSH_OPTS # add options to be automatically added to the ssh command here. # example #ADD_OPTIONS=( '-C' ) # empty default ADD_OPTIONS=( ) # The following options to SSH cause it to open a connection and immediately # become a background task. This allow this script to open a local socket # for future invocations of ssh. (use "ControlMaster auto" in ~/.ssh/config) SOCKET_OPTIONS=( '-fN' ) for OPT in "$@"; do # Add list of values to be removed from sshfs ssh options. By default, sshfs # disables X11 forwarding. We're overriding that behavior. case $OPT in "-x") # this and these like this will be removed ;; "-a") ;; "-oClearAllForwardings=yes") ;; *) # These are ok.. add NUM=${#CLEANED_SSH_OPTS[@]} CLEANED_SSH_OPTS[$NUM]="$OPT" ;; esac done # For some reason, I needed to generate strings of the ssh command before # passing it on as an argument to the 'su' command. It simply would not # work otherwise. # Throwing the $SOCKET_OPTIONS in with the rest of the arguments is kind # of hackish, but it seems to handily override any other specified behavior. # Establishes an ssh socket if none exists... SSH_SOCKET_CMD="ssh $SOCKET_OPTIONS $ $" su localuser -c "$SSH_SOCKET_CMD" # ...and use that socket to mount the remote host SSH_SSHFS_CMD="ssh $ $" exec su localuser -c "$SSH_SSHFS_CMD" 


And, in case anyone cares: ~/.ssh/config

Host * ControlMaster auto ControlPath /tmp/%u@%l→%r@%h:%p ServerAliveInterval 10 Compression yes Host host1 host1.myschool.edu host2 host2.myschool.edu ForwardX11 yes Ciphers arcfour256,arcfour128,arcfour,blowfish-cbc Host host3 host3.myschool.edu ForwardX11 no Ciphers arcfour256,arcfour128,arcfour,blowfish-cbc