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.