How to execute "systemctl --user" as a different user

Solution Verified - Updated -

Issue

  • Trying to execute systemctl --user as a different user fails with Failed to connect to bus: No such file or directory

    # systemctl --user list-units
    Failed to connect to bus: No such file or directory
    
  • Trying to execute systemctl --user after setting the environment variable XDG_RUNTIME_DIR for the target user fails with Failed to connect to bus: Operation not permitted

    # id -u user1
    1000
    # export XDG_RUNTIME_DIR=/run/user/1000
    # systemctl --user list-units
    Failed to connect to bus: Operation not permitted
    

Environment

  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9
    • systemd (user instance)
    • sudo / su

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content