1

Where can I find details on how a user was created. And what is the current status of a user.

For example, adduser command can be run with --no-create-home, --disabled-password, --home DIR etc.

Is there any command which tells if a user has home directory or not. If it has home directory then what is the location of the directory.

Or if a user has password or not.

3
  • See unix.stackexchange.com/questions/636503/…. Home dir can be found in /etc/passwd
    – Panki
    Jan 30, 2022 at 15:07
  • Use getent passwd the_user Read man -a passwd and man getent.
    – waltinator
    Jan 30, 2022 at 15:10
  • note that some systems (e.g. the Debian I looked at) have the home directory set to something like /nonexistent for system users that don't need it, so you may want to check if the named directory actually exists too, not just if the field is nonempty.
    – ilkkachu
    Jan 30, 2022 at 15:40

1 Answer 1

2

See man 5 passwd for the format of password entries. Each user has a number of fields, separated by colons. The home directory is the sixth field, so

getent passwd user | cut -d: -f6

will show user’s home directory. That doesn’t imply that the directory exists; you need to check that separately.

homedir="$(getent passwd user | cut -d: -f6)"; [ -d "$homedir" ] && printf "User %s's home directory is %s and exists.\n" user "$homedir"

The password is the second field. It will usually be x, meaning that the password hash is in /etc/shadow, or *, meaning that password access is disabled for that account (* can also be found in /etc/shadow). You should really use passwd to determine whether an account is disabled; see this answer for details.

[ "$(passwd -S user | cut -d\  -f2)" = P ] && printf "User %s has a password.\n" user
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .