🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](spwd.xhtml "spwd --- The shadow password database") | - [上一页](posix.xhtml "posix --- The most common POSIX system calls") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [Unix 专有服务](unix.xhtml) » - $('.inline-search').show(0); | # [`pwd`](#module-pwd "pwd: The password database (getpwnam() and friends). (Unix)") --- 用户密码数据库 - - - - - - 此模块可以访问 Unix 用户账户名及密码数据库,在所有 Unix 版本上均可使用。 密码数据库中的条目以元组对象返回,属性对应 `passwd` 中的结构(属性如下所示,可参考 `<pwd.h>`): 索引 属性 意义 0 `pw_name` 登录名 1 `pw_passwd` 密码,可能已经加密 2 `pw_uid` 用户 ID 数值 3 `pw_gid` 组 ID 数值 4 `pw_gecos` 用户名或备注 5 `pw_dir` 用户主目录 6 `pw_shell` 用户的命令解释器 其中 uid 和 gid 是整数,其他是字符串,如果找不到对应的项目,抛出 [`KeyError`](exceptions.xhtml#KeyError "KeyError") 异常。 注解 传统的 Unix 系统中,`pw_passwd` 的值通常使用 DES 导出的算法加密(参阅 [`crypt`](crypt.xhtml#module-crypt "crypt: The crypt() function used to check Unix passwords. (Unix)") 模块)。不过现在的 unix 系统使用 *影子密码* 系统。在这些 unix 上,*pw\_passwd* 只包含星号(`'*'`)或字母(`'x'`),而加密的密码存储在文件 `/etc/shadow` 中,此文件不是全局可读的。在 *pw\_passwd* 中是否包含有用信息是系统相关的。如果可以访问到加密的密码,就需要使用 [`spwd`](spwd.xhtml#module-spwd "spwd: The shadow password database (getspnam() and friends). (Unix)") 模块了。 本模块定义如下内容: `pwd.``getpwuid`(*uid*)给定用户的数值 ID,返回密码数据库的对应项目。 `pwd.``getpwnam`(*name*)给定用户名,返回密码数据库的对应项目。 `pwd.``getpwall`()返回密码数据库中所有项目的列表,顺序不是固定的。 参见 模块 [`grp`](grp.xhtml#module-grp "grp: The group database (getgrnam() and friends). (Unix)")针对用户组数据库的接口,与本模块类似。 模块 [`spwd`](spwd.xhtml#module-spwd "spwd: The shadow password database (getspnam() and friends). (Unix)")针对影子密码数据库的接口,与本模块类似。 ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](spwd.xhtml "spwd --- The shadow password database") | - [上一页](posix.xhtml "posix --- The most common POSIX system calls") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python 标准库](index.xhtml) » - [Unix 专有服务](unix.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。