Pass username to systemd unit running as root

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








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?







share|improve this question
















  • 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














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?







share|improve this question
















  • 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












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?







share|improve this question












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?









share|improve this question











share|improve this question




share|improve this question










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












  • 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















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Which professions warranted travel in Medieval times?

How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

Trouble downloading packages list due to a “Hash sum mismatch” error