Is there a non-root shell command that can tell me if a user's account is disabled or not?

Please note that there is a fine distinction between LOCKING and DISABLED:

  • LOCKING is where you prepend ! or * or !! to the password field of the /etc/passwd file. On Linux systems that shadow the passwords, this marker flag may be placed in /etc/shadow instead of /etc/passwd. Password locking can be done (at a shell prompt) via password -l username (as root) to lock the account of username, and the use of the option -u will unlock it.
  • DISABLING an account is done by setting the expiration time of the user account to some point in the past. This can be done with chage -E 0 username, which sets the expiration date to 0 days after the Unix epoch. Setting it to -1 will disable the use of the expiration date.

The effect of locking to to prevent the login process from using a supplied password to hash correctly against the saved hash (by virtue of the fact that the pre-pended marker character(s) are not valid output character(s) for the hash, thus no possible input can ever be used to generate a hash that would match it). The effect of disabling is to prevent any process from using an account because the expiration date of the account has already passed.

For my situation, the use of locking is not sufficient because a user might still be able to login, e.g. using ssh authentication tokens, and processes under that user can still spawn other processes. Thus, we have accounts that are enabled or disabled, not just locked. We already know how to disable and enable the account - it requires root access and the use of chage, as shown above.

To repeat my question: is there a shell command which can be run without root privileges which can output the status of this account expiration info for a given user?

If it helps any, this is intended for use on a Red Hat Enterprise 5.4 system. The output is being returned to a java process which can then parse the output as needed, or make use of the return code.

link|improve this question
I can cat my /etc/passwd file as a non-root user. Can you not do the same? – Doc Aug 10 '11 at 19:22
@Doc - Can you comment on the difference between LOCKED and DISABLED? The passwd file does not contain the account expiration info as I understand it. I mention this in my question body. – weiji Aug 10 '11 at 19:35
feedback

2 Answers

You can use read the /etc/passwd file in a text editor to see whose accounts are locked.

link|improve this answer
In my question body, I mention the /etc/passwd file. I also point out the difference between locked and disabled, and I'm asking for disabled. Lastly, I specifically asked for a shell command. Your answer is not helpful because it does not account for these 3 details - it seems you are just giving a "fastest gun in the west" response. – weiji Aug 10 '11 at 19:43
You're not likely to get many responses to your question with comments like that. Maybe Google would be a better choice for you. – Joe Internet Aug 10 '11 at 20:05
It's because I spent a lot of time and effort on Google already that a knee-jerk answer is not appreciated. There's some truth to your statement, but it's also true that sloppy responses are a waste of everyone else's time. – weiji Aug 10 '11 at 20:39
feedback

No, there isn't. As a non privileged user it would be a potential security risk too allow such users access to /etc/shadow. I believe that for all modern linux distributions password hashes and additional account info has been moved to /etc/shadow from /etc/passwd to eliminate a security hole. If your system uses shadow passwords the "!" at the beginning of a password hash will only be visible and present in /etc/shadow and therefore no accessible to a regular, non-privileged user.

link|improve this answer
I have edited my question to clarify the difference between locking and disabling. – weiji Aug 11 '11 at 17:35
Locked or disabled, issue remains the same, that information is stored in /etc/shadow and therefore inaccessible to non-privileged user. However, since you are using RHEL look into setting up a system account and give it read permission on /etc/shadow via ACL. – Terpion Aug 12 '11 at 12:48
feedback

Your Answer

 
or
required, but never shown

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