passwd
权限与归属
用法
passwd [user]修改登录密码并把哈希写进 /etc/shadow;macOS 几乎没有 Linux 那些选项,改用 dscl 或系统设置。
常用选项
| 选项 | 含义 |
|---|---|
| -S | Linux: show the status of the account |
| -l | Linux: lock the account so the password cannot be used |
| -u | Linux: unlock it again |
| -e | Linux: expire the password so it must change at next login |
| -d | Linux: delete the password outright, which is dangerous |
示例
passwdChanges your own password; it asks for the old one first.
sudo passwd deploySets another user password without knowing the old one.
sudo passwd -l olduserLocks the account.
数字模式和符号模式说的是同一件事:755 和 u=rwx,go=rx 是同一个权限。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. passwd 是做什么的?
修改登录密码并把哈希写进 /etc/shadow;macOS 几乎没有 Linux 那些选项,改用 dscl 或系统设置。
Q. 怎么写?
passwd [user] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 5 个,完整列表在 man passwd。这条命令属于权限与归属。
相关命令
man 手册: man passwd