[systemd-devel] Mounting cifs per-user

Lennart Poettering lennart at poettering.net
Tue Feb 4 11:59:02 PST 2014


On Sat, 01.02.14 23:47, Dan Tihelka (dtihelka at gmail.com) wrote:

> Hello all,
> I have rather generic idea/question which probably not solvable yet.
> 
> I, as an ordinary user, would like to mount cifs share (but it can generally 
> be extended to any other "dynamic" media) on-demand to a given path 
> (preferably /run/mount/UID/mycifs/).
> 
> Currently, mount -t cifs ... must be called as root, although I can specify 
> uid=,gid= to set the ownership of the mountpoint. Therefore, the 
> mount+automount units must belong to the system instance, not to the user 
> instance of systemd. Is it correct?

If cifs mounts require privs then yes, this must be done by the system
systemd instance, not the user one.

> 
> I am able to create a moutnt mnt-storage_user.mount
> 
> 	[Unit]
> 	Wants=network.target
> 	After=network.target
> 
> 	[Mount]
> 	What=//addr/user
> 	Where=/mnt/storage_user
> 	Type=cifs
> 
> 
> and mnt-shared.automount:
> 
> 	[Install]
> 	WantedBy=multi-user.target
> 
> configs.

The place for remot mounts is remote-fs.target, not multi-user.target.

> Now, I would like to make the mount unit generic, something like:
> 
> 	[Mount]
> 	What=//addr/%u
> 	Where=/run/mount/%U/storage_%u

%u/%U are resolved to the user specified in User=. However, you cannot
use it to do NSS lookups in the system instance of systemd, which means
%u only works if you specify User= with a user name, while %U will only
work if you specifiy User= numerically. (Well, with one addition, the
translation of 0 to root and back will always work, as special case).

I figure the best approach for such a generic thing would be to use the
normal autofs daemon, which can do establish generic mounts for this,
per user.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list