Posted: . At: 11:56 AM. This was 10 months ago. Post ID: 18222
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to use Systemd to get information about user sessions on Fedora Linux.


Getting user information from a Linux system is very easy with Fedora-based distributions. Systemd makes this very simple.

Systemd is a system and service manager for Linux operating systems. It initializes and manages/maintains services, but it does not directly provide the functionality to get user information.

However, loginctl, which is part of the systemd suite, can be used to list user sessions:

┏jcartwright@localhost┋ ~━━┓
┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛[11:28] ▓▒░┋ loginctl
SESSION  UID USER        SEAT  TTY 
      2 1000 jcartwright seat0 tty2
 
1 sessions listed.

You can then use the show-user option with a specific username or ID to get more detailed information about that user’s sessions:

┏jcartwright@localhost┋ ~━━┓
┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛[11:28] ▓▒░┋ loginctl show-user jcartwright
UID=1000
GID=1000
Name=jcartwright
Timestamp=Wed 2023-07-05 05:21:18 AEST
TimestampMonotonic=658398278
RuntimePath=/run/user/1000
Service=user@1000.service
Slice=user-1000.slice
Display=2
State=active
Sessions=2
IdleHint=no
IdleSinceHint=0
IdleSinceHintMonotonic=0
Linger=no

This command would display detailed information about the root user’s session.

Please note that these commands may require appropriate permissions (you may need sudo) depending on the system configuration.

This will not work for the user root. It requires root access.

┏jcartwright@localhost┋ ~━━┓
┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛[11:28] ▓▒░┋ loginctl show-user root
Failed to get user: User ID 0 is not logged in or lingering

But this would be very useful for getting information about all logged-in user sessions.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.