LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 07-03-2022, 05:26 AM   #1
Ninguém
LQ Newbie
 
Registered: Feb 2011
Location: localhost
Distribution: GNU/Linux
Posts: 24
Blog Entries: 8

Rep: Reputation: Disabled
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):
Code:
[Unit]
Description=projects
After=gnome-keyring-daemon.service

[Mount]
What=%u@host:/srv/projects
Where=/srv/projects
Type=fuse.sshfs
Options=ServerAliveInterval=45,ServerAliveCountMax=2,reconnect,noatime

[Install]
WantedBy=default.target
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

Last edited by Ninguém; 07-03-2022 at 01:15 PM. Reason: Added answer by teckk
 
Old 07-03-2022, 09:34 AM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Basic info:
https://wiki.archlinux.org/title/SSHFS#On_boot
 
Old 07-03-2022, 09:46 AM   #3
Ninguém
LQ Newbie
 
Registered: Feb 2011
Location: localhost
Distribution: GNU/Linux
Posts: 24

Original Poster
Blog Entries: 8

Rep: Reputation: Disabled
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.
 
Old 07-03-2022, 10:20 AM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Write a script then. Either run that script or have that script run at user login.

What distribution are you using? Either look at your docs for help on systemd units, or
https://www.digitalocean.com/communi...and-unit-files
https://man.archlinux.org/man/systemd.unit.5
https://unix.stackexchange.com/quest...ipt-in-systemd
https://stackoverflow.com/questions/...-a-bash-script

Which is what you are attempting in post #1.
 
Old 07-03-2022, 01:54 PM   #5
Ninguém
LQ Newbie
 
Registered: Feb 2011
Location: localhost
Distribution: GNU/Linux
Posts: 24

Original Poster
Blog Entries: 8

Rep: Reputation: Disabled
I have been running trough your links but I am not able to get any hints!
Edited the first post to mention the distro (Debian).
 
Old 07-05-2022, 05:12 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Quote:
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.
 
Old 07-05-2022, 05:29 PM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by michaelk View Post
Yet you need to be root (or via sudo) to create the systemd mount service so that does not make much sense.
Really? OP already stated that if the unit is started manually it works.
 
Old 07-05-2022, 05:40 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by Ninguém View Post
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):
Code:
[Unit]
Description=projects
After=gnome-keyring-daemon.service

[Mount]
What=%u@host:/srv/projects
Where=/srv/projects
Type=fuse.sshfs
Options=ServerAliveInterval=45,ServerAliveCountMax=2,reconnect,noatime

[Install]
WantedBy=default.target
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).

HTH,

Evo2.
 
Old 07-05-2022, 05:49 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
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.
 
Old 07-05-2022, 06:06 PM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by michaelk View Post
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.

Last edited by evo2; 07-05-2022 at 06:07 PM.
 
Old 07-06-2022, 01:55 AM   #11
Ninguém
LQ Newbie
 
Registered: Feb 2011
Location: localhost
Distribution: GNU/Linux
Posts: 24

Original Poster
Blog Entries: 8

Rep: Reputation: Disabled
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?...
:-/
 
Old 07-06-2022, 06:47 AM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
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.
 
  


Reply

Tags
login, mount, sshfs, systemd



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do we get my UNIT(service) name in unit.sevice Boobalan M Linux - Software 6 01-23-2018 05:03 AM
Using SSHFS with DEVUAN (non Systemd)? Xeratul Linux - General 7 04-27-2017 10:39 AM
[SOLVED] systemd unit does not load at startup. manual start shows no such file/dir failure zjmarlow Linux - Newbie 9 07-19-2015 06:19 AM
LXer: Hybrid RAID 1 (Mirror) of RAM drive & SATA HDD Using LVM with LUKS [and systemd unit file] on LXer Syndicated Linux News 0 07-29-2014 10:40 AM
Storage unit and IO unit salmanucit Linux - General 2 06-17-2008 11:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration