/etc/passwd

From LQWiki
Jump to navigation Jump to search

/etc/passwd is the main location for storing usernames in unix/linux. On older systems one-way encrypted passwords are also stored here, but are now generally stored in /etc/shadow

The file is usually only writable by root for security reasons, although it is readable by everyone, so it can be used for authenticating users by programs such as chroot, su, login etc

the file is text based with colon separating fields and newline separating records. The record structure is

username:passwordindicator:userid:groupid:user details (comma separated):home directory:users shell

The user details is a sub-record comma separated containing user name, user room, user work phone, user home phone, other info but none of these fields are required. For example:

fred:x:110:110:fred blogs,,,:/home/fred:/bin/bash

The password indicator is x for a password in the shadow file, and omitted for no password. The userid 0 is the root ie superuser id. similarly the group id 0 is the same, so if you wanted to give fred superuser permissions, you could change his entry in /etc/passwd to:

fred:x:0:110:fred blogs,,,:/home/fred:/bin/bash

Some system processes have their own ids. For example lp, haldaemon, sshd, messagebus etc. to stop users logging in directly as these processes, their shell is set to something else such as /bin/false

Security note Because /etc/passwd contains user names and their id's it is important not to share this file over your network.