Seamless SFTP Filesystem Mounts via Systemd

Configurare noua (How To)

Situatie

You regularly work with files on a remote server but want them to behave like local files (for editors, scripts, etc.). You don’t have sudo access, so you can’t edit /etc/fstab.

Solutie

Solution Overview:

Use sshfs to mount a remote directory, and systemd user mounts to make the mount persistent across reboots or logins.

Steps:

  1. Install sshfs:

sudo apt install sshfs
  1. Create the mount directory:

mkdir -p ~/mnt/remote
  1. Create a systemd mount unit:

mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/mnt-remote.mount

Paste this:

[Unit]
Description=Mount remote directory via SSHFS
[Mount]
What=username@your.server.com:/path/to/remote
Where=%h/mnt/remote
Type=fuse.sshfs
Options=IdentityFile=%h/.ssh/id_rsa,allow_other,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3

[Install]
WantedBy=default.target

  1. Enable and start the mount:

systemctl --user daemon-reload
systemctl --user enable --now mnt-remote.mount
  1. Verify:

ls ~/mnt/remote

You should see your remote files as if they were local.

Use Cases:

  • Live-edit remote code in VSCode or Vim without setting up SFTP plugins

  • Backup/sync data easily with rsync or GUI tools

  • Automatically mount shared development folders on login.

Tip solutie

Permanent

Voteaza

(2 din 4 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?