Advanced Programming in
the UNIX Environment
Week 04, Segment 5: /etc/passwd
Department of Computer Science
Stevens Institute of Technology
Jan Schaumann
[email protected]
https://stevens.netmeister.org/631/
CS631 - Advanced Programming in the UNIX Environment
/etc/passwd
Called a user database by POSIX and usually found in /etc/passwd, the password file
contains the following fields:
Description struct passwd member POSIX.1
username char *pw_name ✅
hashed password char *pw_passwd
numerical UID uid_t pw_uid ✅
numerical GID gid_t pw_gid ✅
comment char *pw_gecos
initial working directory char *pw_dir ✅
initial shell char *pw_shell ✅
2
Jan Schaumann 2020-09-23
CS631 - Advanced Programming in the UNIX Environment
/etc/passwd
root:*:0:0:Charlie &:/root:/bin/csh pw_name
toor:*:0:0:Bourne-again Superuser:/root:/rescue/sh pw_passwd
pw_uid
daemon:*:1:1:The devil himself:/:/sbin/nologin
pw_gid
operator:*:2:5:System &:/usr/guest/operator:/sbin/nologin
pw_gecos
bin:*:3:7:Binaries Commands and Source:/:/sbin/nologin
pw_dir
games:*:7:13:& pseudo-user:/usr/games:/sbin/nologin pw_shell
postfix:*:12:12:& pseudo-user:/var/spool/postfix:/sbin/nologin
named:*:14:14:& pseudo-user:/var/chroot/named:/sbin/nologin
ntpd:*:15:15:& pseudo-user:/var/chroot/ntpd:/sbin/nologin
sshd:*:16:16:& pseudo-user:/var/chroot/sshd:/sbin/nologin
uucp:*:66:1:UNIX-to-UNIX Copy:/nonexistent:/sbin/nologin
nobody:*:32767:39:Unprivileged user:/nonexistent:/sbin/nologin
jschauma:*:1000:100:Jan Schaumann,Lieb Building,555-1234,555-2233:/home/jschauma:/bin/sh
fred::1001:100:::/bin/sh
drwho:*:1003:100:The Doctor:/home/drwho:/bin/date
alice:*:1004:100::/home/alice:
alice:*:1002:100::/home/alice:/bin/ksh
3
Jan Schaumann 2020-09-23
CS631 - Advanced Programming in the UNIX Environment
/etc/passwd
root:*:0:0:Charlie &:/root:/bin/csh pw_name
toor:*:0:0:Bourne-again Superuser:/root:/rescue/sh pw_passwd
pw_uid
daemon:*:1:1:The devil himself:/:/sbin/nologin
pw_gid
operator:*:2:5:System &:/usr/guest/operator:/sbin/nologin
pw_gecos
bin:*:3:7:Binaries Commands and Source:/:/sbin/nologin
pw_dir
games:*:7:13:& pseudo-user:/usr/games:/sbin/nologin pw_shell
postfix:*:12:12:& pseudo-user:/var/spool/postfix:/sbin/nologin
named:*:14:14:& pseudo-user:/var/chroot/named:/sbin/nologin
ntpd:*:15:15:& pseudo-user:/var/chroot/ntpd:/sbin/nologin
sshd:*:16:16:& pseudo-user:/var/chroot/sshd:/sbin/nologin
uucp:*:66:1:UNIX-to-UNIX Copy:/nonexistent:/sbin/nologin
nobody:*:32767:39:Unprivileged user:/nonexistent:/sbin/nologin
jschauma:*:1000:100:Jan Schaumann,Lieb Building,555-1234,555-2233:/home/jschauma:/bin/sh
fred::1001:100:::/bin/sh
drwho:*:1003:100:The Doctor:/home/drwho:/bin/date
alice:*:1004:100::/home/alice:
alice:*:1002:100::/home/alice:/bin/ksh
4
Jan Schaumann 2020-09-23
CS631 - Advanced Programming in the UNIX Environment
System Databases
5
Jan Schaumann 2020-09-23
CS631 - Advanced Programming in the UNIX Environment
/etc/passwd
• Most fields in the password database may be empty:
• empty password field: anybody can log in (probably a mistake)
• empty home directory field: use / instead
• empty shell field: use /bin/sh instead
• Entries may be duplicated:
• same GID: multiple users in the same primary group (normal)
• same UID: system applies same permissions for all accounts (rarely used)
• same username: system will pick one or the other (almost always a mistake)
6
Jan Schaumann 2020-09-23