# How to list the current active login sessions?



## tempurabeef (Nov 24, 2020)

Hi all,

I'm trying to list all the users that are currently logged in to the system, and information about their login session (tty or ssh, etc.). Basically something similar to what `loginctl` would show on a Linux machine.

How can I achieve this in FreeBSD?

Thanks!


----------



## Argentum (Nov 24, 2020)

tempurabeef said:


> Hi all,
> 
> I'm trying to list all the users that are currently logged in to the system, and information about their login session (tty or ssh, etc.). Basically something similar to what `loginctl` would show on a Linux machine.
> 
> ...


Use the command `w`.

Manual: w(1)


----------



## Phishfry (Nov 24, 2020)

`ps -aux`


----------



## ralphbsz (Nov 24, 2020)

The w command is ancient, and the historically accepted way to do this. To a large extent that's because it looks at the utmp file (which on FreeBSD is not actually called utmp), and therefore can get a pretty much ACID-correct look at the list of logged in users.

On modern Linux (last two years or so), loginctl has the same functionality, and for the same reason: on a systemd equipped machine, all logins go through systemd, so loginctl (part of the systemd utilities) can see a live status of who is logged in. I think on a systemd based Linux, the implementation of w ends up being a wrapper around loginctl. Why does loginctl even exists? Answering that would require a long rant about Lennart, and how he confuses his personal debugging tools with useful utilities, and how he wouldn't know what "requirements" are if someone shoved them up his ..., and how he disdains but imitates long standing traditions, so let's not go there.



Phishfry said:


> `ps -aux`


Yes, but ... interpreting the output of ps requires knowledge, while w gives you the important part of the answers all pre-cooked. The two tools are overlapping yet orthogonal.


----------



## SirDice (Nov 24, 2020)

Besides w(1), there's also the venerable who(1). Also an 'old' tool, the difference is that who(1) is defined in POSIX, w(1) is not (it stems from an early BSD implementation).


----------



## ShelLuser (Nov 25, 2020)

In addition to the above I prefer users(1), its output is a little easier for scripting.


----------



## tempurabeef (Nov 25, 2020)

ralphbsz said:


> The w command is ancient, and the historically accepted way to do this. To a large extent that's because it looks at the utmp file (which on FreeBSD is not actually called utmp), and therefore can get a pretty much ACID-correct look at the list of logged in users.


Thanks for the insights! One question: What is "ACID-correct"?


----------



## tempurabeef (Nov 25, 2020)

Thanks for all the replies. After reading through the man pages for `w` and `who`, I'm starting to wonder what being "logged in" really means from the operating system's perspective. I mean, the user `ntpd` isn't considered to be "logged in" even if there is a ntpd process running, but a regular user is considered to be "logged in" when they are running some commands in a shell.

Is it the type of program being run that decides whether it is considered to be a "login session", or is it something else?


----------



## Argentum (Nov 25, 2020)

tempurabeef said:


> Thanks for all the replies. After reading through the man pages for `w` and `who`, I'm starting to wonder what being "logged in" really means from the operating system's perspective. I mean, the user `ntpd` isn't considered to be "logged in" even if there is a ntpd process running, but a regular user is considered to be "logged in" when they are running some commands in a shell.
> 
> Is it the type of program being run that decides whether it is considered to be a "login session", or is it something else?


Login usually means somebody is logging in through terminal.

See also `last` and `lastlogin`
Man last(1), lastlogin(8)


----------



## SirDice (Nov 25, 2020)

tempurabeef said:


> What is "ACID-correct"?


Atomicity, Consistency, Isolation, Durability.


----------

