systemd mount unit using sshfs not mounting on login
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
systemd mount unit using sshfs not mounting on login
I am trying to mount dir projects using sshfs on login.
My key does use a passphrase that I cache using gnome-keyring.
Here is my mount unit (srv-projects.mount):
Thank you, but I don't want to mount at boot time. I want to mount it at login.
Besides I should not need to be root (the intended behavior is to have it run as a regular user with no right to mess around with fstab).
When I issue the command:
Code:
$ systemctl --user start srv-projects.mount
afterwords, it does work. I just didn't want to have to do that every time.
Besides I should not need to be root (the intended behavior is to have it run as a regular user with no right to mess around with fstab).
Yet you need to be root (or via sudo) to create the systemd mount service so that does not make much sense.
Depends on distribution and shell you are running but with bash you can add the sshfs command to mount in the ~/.bashrc for login and the unmount (fusermount) command to the users ~/.bash_logout file.
I am trying to mount dir projects using sshfs on login.
My key does use a passphrase that I cache using gnome-keyring.
Here is my mount unit (srv-projects.mount):
The unit fails on login whith the following error messages:
Code:
srv-projects.mount: Failed with result 'exit-code'.
Failed to mount projects.
But if i, then, try starting the unit, it does mount with no errors.
What am I doing wrong?
Distro: Debian
My guess is that "After=gnome-keyring-daemon.service" is not sufficient to ensure that the keyring has been unlocked. I would suggest looking into how to increase verbosity: eg add options
Code:
ssh_command=ssh\040-vv,sshfs_debug,debug
And then checking
Code:
journalctl -u srv-projects.mount
You could also try using a key that is not protected by a passphrase (just for testing).
The OP wants to mount a remote directory on login and unmount it on logout. You don't need to create a systemd mount or add an entry to the /etc/fstab file.
The OP created a duplicate thread which also includes additional requirements.
Quote:
Ended up creating a desktop file under ~/.config/autostart. but it's an ugly hack with undesirable consequences (doesn't unmount on logout, for example).
Can you help me get systemd to mount my sshfs mount?
- As a regular user (not root)
- No fstab manipulation
There is no need to use systemd or fstab. As already posted you only need to add the command to the login and logout scripts which are in the user's home directory.
I use /etc/fstab because I prefer to have the remote directory automatically mounted when accessed and automatically unmounted after an idle timeout.
There is no need to use systemd or fstab. As already posted you only need to add the command to the login and logout scripts which are in the user's home directory.
There are many things that can be done with systemd users units, that can also be done other ways. OP is specifically asking about using systemd for this.
While it is true that it can be done another way it doesn't actually answer the question.
I used to do bunch of stuff with login and logout scripts. I've found that systemd user units are a great replacement for most of them. As such I'm slowly migrating them over to systemd units, so I understand why OP wants to solve this.
Thank you both evo2 and michaelk. That's right - I do would like to use systemd for this. Systemd user units should do, but seemingly they don't.
I should have stated that I'm using gnome-shell, so .bashrc and .bash_logout wouldn't work. I'm having a similar war over setting up umask 0022 to the entire gnome-session!
Ideally it all should just work with a mount and an automount unit.
I'm gravitating more to the conclusion that the systemd instance instantiated by user login has additional restrictions regarding mount units that the system wide one doesn't (security reasons?).
I already tried setting up a passwordless key and it still didn't work. But then... why would it work afterwords?!...
Read today that Lennart Poettering is leaving redhat. I wonder what will happen to systemd, now.
I wish I understood more about dbus. It seems to me dbus is some kind of wizardry that can, maybe, "talk" to the system wide instance of systemd and ask it to mount? Could it set my umask as well?...
:-/
In my particular case I do not have a passphrase so gnome-keyring is not a player. If I do not include the key as IdentityFile=... as an option in the unit file the remote directory will not mount upon login but does once logged in and run as posted.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.