Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XDG_RUNTIME_DIR isn't set for root user, logged in via sudo inside SSH session #601

Closed
danbst opened this issue Mar 3, 2019 · 5 comments

Comments

@danbst
Copy link

danbst commented Mar 3, 2019

My setup (pretty scary):

  • Ubuntu 18.04
  • connect to remote host as ubuntu user
  • sudo su - to obtain root
  • home-manager with some 18.09 checkout installed into root-s home
  • custom user service defined
  • linger enabled:
    home.activation.linger = dag.entryBefore ["reloadSystemD"] ''
        loginctl enable-linger $USER
    '';

I get a problem that systemctl --user can't reach DBus:

root@nomad-02:~# systemctl --user -a
Failed to connect to bus: No such file or directory

I fix it with

    home.sessionVariables.XDG_RUNTIME_DIR = "/run/user/$UID";

but I wonder why this isn't default.

@wedens
Copy link

wedens commented Dec 28, 2019

You don't even need to do that remotely.

Doing something like sudo -u other_user zsh -c 'systemctl --user show-environment' will result in the same problem. Providing XDG_RUNTIME_DIR makes it work.

@rycee
Copy link
Member

rycee commented Dec 28, 2019

Seems this is (mostly) by design. See, e.g., systemd/systemd#7451 (comment)

Specifically, the su and sudo PAM configurations intentionally don't include pam_systemd.so (at least on NixOS) so XDG_RUNTIME_DIR will not be set for those commands. You can bypass this by setting XDG_RUNTIME_DIR as you've found out but reading Poettering's response it seems to me that this comes with implications that makes it a bad idea to include it by default in HM.

Using machinectl does indeed seem to work to give you a proper login shell with a functional systemd. E.g.

$ machinectl shell test@

to make a login shell for the user "test" on the local system. So I would suggest using machinectl instead of sudo when you want a full login shell with a user systemd session. This seems like an extra good idea for root logins since the machinectl way appears to isolate the root login more from your user login.

@danbst
Copy link
Author

danbst commented Dec 28, 2019

interesting. So sudo su - considered wrong, use sudo machinectl shell root@...

@wedens
Copy link

wedens commented Dec 28, 2019

One of the problems with machinectl shell is that it doesn't propagate exit code, if you care about it. man says that systemd-run should be used in this case, but I can't figure out the correct way to use it.

@stale
Copy link

stale bot commented Apr 29, 2021

Thank you for your contribution! I marked this issue as stale due to inactivity. If this remains inactive for another 7 days, I will close this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

If you have nothing of substance to add, please refrain from commenting and allow the bot close the issue. Also, don't be afraid to manually close an issue, even if it holds valuable information.

Closed issues stay in the system for people to search, read, cross-reference, or even reopen--nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Apr 29, 2021
@stale stale bot closed this as completed May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants