Pass username to systemd unit running as root
up vote
3
down vote
favorite
I'm trying to write my first systemd unit. I want to dynamically mount some places based on the username at login like /mnt/$USER/folder and not though fstab. I cannot get $USER or $LOGNAME to the script via systemd because root user is required to issue the mount command so those always expand to "root".
I have tried Environment=, EnvironmentFile=, passing $USER in ExecStart instead of in the called script, and they all pass "$USER" literally rather than the actual username. If I run the service as a user, the mount fails because the user isn't root.
I'm hoping not to reconfigure the entire system for this one task.
Any suggestions?
systemd
add a comment |Â
up vote
3
down vote
favorite
I'm trying to write my first systemd unit. I want to dynamically mount some places based on the username at login like /mnt/$USER/folder and not though fstab. I cannot get $USER or $LOGNAME to the script via systemd because root user is required to issue the mount command so those always expand to "root".
I have tried Environment=, EnvironmentFile=, passing $USER in ExecStart instead of in the called script, and they all pass "$USER" literally rather than the actual username. If I run the service as a user, the mount fails because the user isn't root.
I'm hoping not to reconfigure the entire system for this one task.
Any suggestions?
systemd
2
to me this sounds like a task for pam_mount (manpages.ubuntu.com/manpages/bionic/man8/pam_mount.8.html), not systemd.
â Sebastian Stark
May 23 at 23:24
Thanks, I'll look into that. Sounds like exactly what I need. I didn't want to use xinit like in the past.
â Stuart K. Smith
May 24 at 12:12
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I'm trying to write my first systemd unit. I want to dynamically mount some places based on the username at login like /mnt/$USER/folder and not though fstab. I cannot get $USER or $LOGNAME to the script via systemd because root user is required to issue the mount command so those always expand to "root".
I have tried Environment=, EnvironmentFile=, passing $USER in ExecStart instead of in the called script, and they all pass "$USER" literally rather than the actual username. If I run the service as a user, the mount fails because the user isn't root.
I'm hoping not to reconfigure the entire system for this one task.
Any suggestions?
systemd
I'm trying to write my first systemd unit. I want to dynamically mount some places based on the username at login like /mnt/$USER/folder and not though fstab. I cannot get $USER or $LOGNAME to the script via systemd because root user is required to issue the mount command so those always expand to "root".
I have tried Environment=, EnvironmentFile=, passing $USER in ExecStart instead of in the called script, and they all pass "$USER" literally rather than the actual username. If I run the service as a user, the mount fails because the user isn't root.
I'm hoping not to reconfigure the entire system for this one task.
Any suggestions?
systemd
asked May 23 at 23:02
Stuart K. Smith
8613
8613
2
to me this sounds like a task for pam_mount (manpages.ubuntu.com/manpages/bionic/man8/pam_mount.8.html), not systemd.
â Sebastian Stark
May 23 at 23:24
Thanks, I'll look into that. Sounds like exactly what I need. I didn't want to use xinit like in the past.
â Stuart K. Smith
May 24 at 12:12
add a comment |Â
2
to me this sounds like a task for pam_mount (manpages.ubuntu.com/manpages/bionic/man8/pam_mount.8.html), not systemd.
â Sebastian Stark
May 23 at 23:24
Thanks, I'll look into that. Sounds like exactly what I need. I didn't want to use xinit like in the past.
â Stuart K. Smith
May 24 at 12:12
2
2
to me this sounds like a task for pam_mount (manpages.ubuntu.com/manpages/bionic/man8/pam_mount.8.html), not systemd.
â Sebastian Stark
May 23 at 23:24
to me this sounds like a task for pam_mount (manpages.ubuntu.com/manpages/bionic/man8/pam_mount.8.html), not systemd.
â Sebastian Stark
May 23 at 23:24
Thanks, I'll look into that. Sounds like exactly what I need. I didn't want to use xinit like in the past.
â Stuart K. Smith
May 24 at 12:12
Thanks, I'll look into that. Sounds like exactly what I need. I didn't want to use xinit like in the past.
â Stuart K. Smith
May 24 at 12:12
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1039592%2fpass-username-to-systemd-unit-running-as-root%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
to me this sounds like a task for pam_mount (manpages.ubuntu.com/manpages/bionic/man8/pam_mount.8.html), not systemd.
â Sebastian Stark
May 23 at 23:24
Thanks, I'll look into that. Sounds like exactly what I need. I didn't want to use xinit like in the past.
â Stuart K. Smith
May 24 at 12:12