I have a server I connect to using ssh in pantheon-files, how do I make the network file system remain mounted after reboot?
1 Answer
The easy way to mount a filesystem during boot is to list it in /etc/fstab
. However, SSHFS is a FUSE filesystem, so mounting it from a system configuration file is tricky: you wouldn't have permission to access it under your account.
While it's possible to get this done, it's easier to do the mounting from your account.
You can use cron to schedule a task at boot time to mount that filesystem. Run the command crontab -e
to edit the list of scheduled tasks for your account, and add a line:
@reboot sshfs remotehost.example.com:/remote/path /path/to/mount/point
Note that the sshfs
mount command won't have access to any interactive environment, so it won't be able to ask you for a password or for a key passphrase. If you need that, you'll need to arrange to run the command when you log in, not when the system starts.
If the network connection isn't available at boot time, you may want to do the mounting when the network becomes available. To do that, add a file to the if-up.d
directory called john-mount-sshfs
and containing the following code (replace john
by your username, and replace the host name and paths):
#!/bin/sh
su -c john <<'EOF'
if ping -c 1 remotehost.example.com >/dev/null 2>/dev/null; then
sshfs remotehost.example.com:/remote/path /path/to/mount/point
fi
EOF
If you need to supply credentials to the sshfs
command, then autosshfs is likely to be more convenient. It mounts the directory on first access, so you can supply the credentials at that time.