Monday, June 29, 2009

HOWTO Check if a user or group already exists

Dont directly check with /etc/passwd, or /etc/group for existence of a user or group. This wont look up NIS database entries. A better way is to use getent, part of glibc. Lookup database entry for an existing user:
getent passwd username1 [username2 ...]
Lookup database entry for an existing group:
getent group groupname1 [groupname2 ...]

No comments: