Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

How does users define what users are logged in?

If I ssh into a box twice, I see my username twice listed if I execute users. However, if I create a new login shell via sudo su -, I do not see root listed as users. Same goes for any other user such as sudo su - user. Of course, a non-login shell also doesn't show up in users.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

users counts login sessions. From sudo:

The su command is used to become another user during a login session.

(Emphasis is mine.) A login session creates a new tty, where as su uses the existing tty.

I just looked at the source code to the users command. What it does is read utmp. So I guess the bottom line is that if you write a program and write to utmp, you'll be seen in users.

share|improve this answer
    
but what about The -i (simulate initial login) in sudo -i? I guess "simulate" is the key word here. Perhaps it's not really doing a login. –  imagineerThis Jun 17 at 0:20
1  
The key thing is allocating a tty. -i doesn't do that. It does run all the startup profiles the same as done after the tty is allocated. –  rocky Jun 17 at 0:24
    
weird. the tty makes it interactive, but can't you have a non-interactive login shell? –  imagineerThis Jun 17 at 0:27
1  
See recent edit. –  rocky Jun 17 at 0:32
    
Makes sense. There are lots of interactive non-login shells that don't show up from users –  imagineerThis Jun 17 at 0:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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