pwd
— The password database¶
This module provides access to the Unix user account and password database. Itis available on all Unix versions.
Availability: Unix, not WASI, not iOS.
Password database entries are reported as a tuple-like object, whose attributescorrespond to the members of thepasswd
structure (Attribute field below,see<pwd.h>
):
Index | Attribute | Meaning |
---|---|---|
0 |
| Login name |
1 |
| Optional encrypted password |
2 |
| Numerical user ID |
3 |
| Numerical group ID |
4 |
| User name or comment field |
5 |
| User home directory |
6 |
| User command interpreter |
The uid and gid items are integers, all others are strings.KeyError
israised if the entry asked for cannot be found.
Note
In traditional Unix the fieldpw_passwd
usually contains a passwordencrypted with a DES derived algorithm. However mostmodern unices use a so-calledshadow password system. On those unices thepw_passwd field only contains an asterisk ('*'
) or the letter'x'
where the encrypted password is stored in a file/etc/shadow
which isnot world readable. Whether thepw_passwd field contains anything useful issystem-dependent.
It defines the following items:
- pwd.getpwuid(uid)¶
Return the password database entry for the given numeric user ID.
- pwd.getpwnam(name)¶
Return the password database entry for the given user name.
- pwd.getpwall()¶
Return a list of all available password database entries, in arbitrary order.
See also
- Module
grp
An interface to the group database, similar to this.