SSHFS - Storage
🔐 SSHFS-Mount Anleitung für Linux + Nextcloud
Beispiele nutzen Fantasie-Namen und RFC-5737-Dummy-IP (192.0.2.0/24):
Client: orion-client • Server: atlas-storage • Server-IP: 192.0.2.55
Zielpfad auf dem Server: /srv/projects/ai/labs/local-sdxl-cpu
0. Voraussetzungen (Server)
# Gruppe für SSHFS-Nutzer anlegen (falls noch nicht vorhanden)
groupadd sshfsusers
# Verzeichnis für hinterlegte Public Keys anlegen und absichern
mkdir -p /etc/sshfs_keys
chown root:root /etc/sshfs_keys
chmod 0755 /etc/sshfs_keys
1. SSH-Schlüssel erstellen (auf dem Client)
# moderner Schlüssel (ed25519)
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/V24_NextCloudorion_to_atlas -C "V24_NextCloudsshfs onorion-client ThinkStation__S4AKHKX__big-bunda"→ atlas-storage"
ssh-keygen -t ed25519 -f /root/.ssh/ -C " on ThinkStation__S4AKHKX__big-bunda"2. Öffentlichen Schlüssel auf den Server übertragen
scp ~/.ssh/V24_NextCloud.orion_to_atlas.pub root@server:root@192.0.2.55:/etc/sshfs_keys/V24_NextCloud.sshfs_orion.pub
# auf dem Server:
chown root:root /etc/sshfs_keys/sshfs_orion.pub
chmod 6440644 /etc/sshfs_keys/V24_NextCloud.sshfs_orion.pub
3. SSHFS-Benutzer auf dem Server anlegen (sicher für SSHFS)
# Benutzer ohne Home (kein Risiko durch dotfiles), in Gruppe sshfsusers
useradd -M -g sshfsusers -s /bin/bashusr/sbin/nologin -Gsshfs_orion
sshfsusers# V24_NextCloudZiel-Verzeichnisstruktur (nur Beispielpfad)
mkdir -p /mnt/sshfs/V24_NextCloudsrv/projects/ai/labs/local-sdxl-cpu
# Eigentümer/Gruppe setzen, setgid auf dem Zielordner
chown V24_NextCloud:V24_NextCloud-R root:sshfsusers /mnt/sshfs/V24_NextCloudsrv/projects
chmod 2750 /srv/projects/ai/labs/local-sdxl-cpu
Wichtig (Traversal nur für die Gruppe): Damit der Benutzer sshfs_orion den Zielordner erreicht, müssen alle Elternordner das x-Recht für die Gruppe haben, ohne Leserechte (kein Listing). Das hält den Pfad geschlossen und erlaubt nur Durchgang.
# Elternordner: Gruppe setzen + nur Durchgang (710)
chgrp sshfsusers /srv
chmod 710 /srv
chgrp sshfsusers /srv/projects
chmod 710 /srv/projects
chgrp sshfsusers /srv/projects/ai
chmod 710 /srv/projects/ai
chgrp sshfsusers /srv/projects/ai/labs
chmod 710 /srv/projects/ai/labs
# OptionaleZielordner: Dummy-Shellnur fürBesitzer+Gruppe, mehrsetgid Sicherheit:damit echoneue -eDateien '#!/bin/bash\nexitin 0'der >Gruppe bleiben
chgrp sshfsusers /usr/local/bin/sshfs-dummysrv/projects/ai/labs/local-sdxl-cpu
chmod +x2770 /usr/local/bin/sshfs-dummy
usermod -s /usr/local/bin/sshfs-dummy V24_NextCloudsrv/projects/ai/labs/local-sdxl-cpu
4. SSH-Konfiguration (angepasstauf fürdem SSHFS)Server
Datei bearbeiten und am Ende hinzufügen:# /etc/ssh/sshd_config
Match User V24_NextCloudsshfs_orion
AuthorizedKeysFile /etc/sshfs_keys/%u.pub
PubkeyAuthentication yes
KbdInteractiveAuthentication no
PasswordAuthentication no
AllowTcpForwarding no
X11Forwarding no
PermitTTY yesno
#PermitTunnel Keinno
ForceCommand setzen, da SSHFS sonst blockiert würdeinternal-sftp
# Syntax prüfen und Dienst neu laden
sshd -t
systemctl reload sshdssh
5. FUSE erlauben (Client & ggf. Server)
Datei /etc/fuse.conf öffnen und sicherstellen, dass die Zeile ohne Kommentar vorhanden ist:
user_allow_other
6. Bequemer Host-Alias auf dem Client (empfohlen)
Datei ~/.ssh/config (Client) ergänzen:
Host atlas
HostName 192.0.2.55
User sshfs_orion
IdentityFile ~/.ssh/orion_to_atlas
IdentitiesOnly yes
ServerAliveInterval 15
ServerAliveCountMax 3
StrictHostKeyChecking yes
7. SSHFS-Mount auf dem Client
# lokaler Mountpunkt
mkdir -p /mnt/atlas_labs
# Mount (streng: others=0 → umask=007)
sshfs -o IdentityFile=~/.ssh/V24_NextCloudorion_to_atlas \
-o reconnect \
-o ServerAliveInterval=15 \
-o ServerAliveCountMax=3 \
-o allow_other \
-o default_permissions \
-o uid=1000 \
-o gid=1000 \
-o umask=002 \
-o idmap=user \
V24_NextCloud@server:/mnt/sshfs/V24_NextCloud /mnt/V24_NextCloud
💡 Hinweis:
/etc/fuse.confuser_allow_otheruidgidid benutzernameumask=002🎁 Bonus: Nutzung mit Nextcloud
Mount für www-data (Nextcloud)
sshfs -o IdentityFile=~/.ssh/nextcloud_key \
-o reconnect \
-o ServerAliveInterval=15 \
-o ServerAliveCountMax=3 \
-o allow_other \
-o uid=33 \
-o gid=33 \
-o umask=007 \
-o idmap=user \
nextcloud@server:atlas:/srv/projects/ai/labs/local-sdxl-cpu /mnt/sshfs/nextcloudatlas_labs
Hinweise:
umask=007 ergibt effektiv 770/660 auf dem Mount (keine Rechte für others). (umask=002 würde 775/664 zulassen.)
default_permissions sorgt dafür, dass Kernel-Rechte lokal erzwungen werden.
8. Optional: Dauerbetrieb per /etc/fstab (Client)
sshfs#sshfs_orion@192.0.2.55:/srv/projects/ai/labs/local-sdxl-cpu /mnt/atlas_labs fuse.sshfs \
IdentityFile=/root/.ssh/orion_to_atlas,allow_other,default_permissions,uid=1000,gid=1000,umask=007, \
reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,idmap=user,_netdev 0 0
🎁 Bonus: Nutzung mit Nextcloud
Mount für www-data (uid/gid 33):
mkdir -p /mnt/nextcloud_data
sshfs -o IdentityFile=/root/.ssh/nextcloud_key \
-o reconnect -o ServerAliveInterval=15 -o ServerAliveCountMax=3 \
-o allow_other -o default_permissions \
-o uid=33 -o gid=33 -o umask=007 -o idmap=user \
nextcloud_svc@192.0.2.55:/srv/nextcloud/export /mnt/nextcloud_data
Wichtig:
www-data/mnt/nextcloud_data/mnt/nextcloud_data einbinden.
Optional für Dauerbetrieb:
Systemd-Mount oder /etc/fstab verwenden, z. B.:
sshfs#nextcloud@server:/mnt/sshfs/nextcloud /mnt/nextcloud_data fuse.sshfs \
IdentityFile=/root/.ssh/nextcloud_key,allow_other,uid=33,gid=33,umask=007,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,idmap=user 0 0
🙋♂️9. HilfeTroubleshooting für(kurz Mehrbenutzer-Zugriff& unter Linuxsicher)
VerwendePasswort-Prompt statt Key: Rechte prüfen:/etc/sshfs_keys= 0755, Dateien = 0644, Owner = root:root. Dannsshd -oTallow_other-C user=sshfs_orion,umaufauchdemanderenServerlokalenundUsernaufZugriffauthorizedkeysfilezu erlaubenachten.NutzeZugriff verweigert trotz korrektem Key: Elternordner-Traversal mituid=namei -l /srv/projects/ai/labs/local-sdxl-cpuundprüfen. Jeder Ordner brauchtgid=g+x,um das Mount für bestimmte Benutzer oder Gruppen bereitzustellen
mediensshfsusers-o allow_other,uid=1000,gid=1002,umask=007usermod~/.ssh/config