1

Is it possible to get the name of an active user in systemd units? I guess I could parse output of who or do something like that, but I believe there should be a native way of doing that in systemd.

I also know there is logind which tells me a bit more information about the users, but if there were more seats, I would like to know who the single user who caused the event was, e.g. if someone wrote systemctl suspend to only lock his session at his seat and let the computer handle all the other seats. It is probably not the best example but I hope it illustrates the problem better, I only want the one user who caused systemd units to run.

Namely I wanted to create a systemd unit that will lock the user's current session when going to sleep and right now I resorted to trying to lock all sessions. I believe this to be a bad solution and would like to know how to do this properly.

marked as duplicate by Stephen Kitt, G-Man, Michael Homer, Jeff Schaller, Stephen Rauch Dec 3 '17 at 15:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @StephenKitt I put some more information there, even though the other question is useful for me, I don't believe it solves my problem as a whole. I was actually already using logind to list all the sessions when locking them, but I would like to know what user/session caused the unit to run – Ordoshsen Dec 3 '17 at 13:12
  • Why are your users running systemctl suspend to lock their session? – Stephen Kitt Dec 4 '17 at 9:43
1

I was wrong and now I know it. Everything systemd oriented is run by root and I just thought it was not because of some experiments I have done earlier.

There is no way to figure out who is sitting at the computer, I can only get the full list of logged users.

  • Except there is a way to figure out who is sitting at the computer... – Stephen Kitt Feb 22 '18 at 8:59
  • @Stephen Kitt and would you share? – Ordoshsen Feb 25 '18 at 12:44
  • See the linked duplicate (and my answer there). – Stephen Kitt Feb 25 '18 at 13:31
  • @StephenKitt to qoute myself from December of last year "I was actually already using logind to list all the sessions [...], but I would like to know what user/session caused the unit to run". I hoped there would be a way to know which user caused the system to run a unit (if it was not something like lid close). logind just narrows the guess if there is more than one session – Ordoshsen Mar 12 '18 at 23:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.