There was a temporary network glitch and all user terminal ssh sessions were broken. Upon logging in to the CentOS server again and running the "w" command lists a higher number of users logged in than they actually. It adds up the users whose session was broken. Manually killed the earlier "pts" sessions. However the number of logged in users is still higher than the actual number now.

Is there any way I can properly kill these disconnected "ssh" sessions to get correct number of logged in users in "w" output?

  • This could help, at least it sounds like the same problem that you have. – Risto Salminen Nov 28 '13 at 10:33

This could be due to corrupted /var/run/utmp file, and if that's the case, it can be repaired with the following command, which is preferred to run in single-user mode, otherwise users who are currently logged in may experience some weird behaviour:

# >/var/run/utmp

That command will clear the contents of file /var/run/utmp, and the # states for root prompt. After that you could reboot your system.

Source: Why does the “w” command report a wrong number of logged in users?

| improve this answer | |
  • 1
    Note the command he's showing there is >/var/run/utmp which will zero out the file, the # is his prompt, which is showing you that you need to be root, or have elevated credentials to do this command. – slm Nov 28 '13 at 18:09
  • @slm Thanks for noticing, I'll add that to my answer. – Risto Salminen Nov 28 '13 at 18:42

This might be caused by a corrupted utmp or utmpx file.

| improve this answer | |

There is really no way for the server to know the difference between a session that was cut off due to a network outage and a session where the user got up and walked away.

Some shells may have a timeout feature where, if the shell does not see any activity for a specified amount of time, it will disconnect the session.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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