- 用户管理
用户管理
创建和删除用户 - useradd / userdel。
[root home]# useradd hellokitty[root home]# userdel hellokitty
-d- 创建用户时为用户指定用户主目录-g- 创建用户时指定用户所属的用户组
创建和删除用户组 - groupadd / groupdel。
说明:用户组主要是为了方便对一个组里面所有用户的管理。
修改密码 - passwd。
[root ~]# passwd hellokittyNew password:Retype new password:passwd: all authentication tokens updated successfully.
说明:输入密码和确认密码没有回显且必须一气呵成的输入完成(不能使用退格键),密码和确认密码需要一致。如果使用
passwd命令时没有指定命令作用的对象,则表示要修改当前用户的密码。如果想批量修改用户密码,可以使用chpasswd命令。-l/-u- 锁定/解锁用户。-d- 清除用户密码。-e- 设置密码立即过期,用户登录时会强制要求修改密码。-i- 设置密码过期多少天以后禁用该用户。
查看和修改密码有效期 - chage。
设置hellokitty用户100天后必须修改密码,过期前15天通知该用户,过期后15天禁用该用户。
chage -M 100 -W 15 -I 15 hellokitty
切换用户 - su。
[root ~]# su hellokitty[hellokitty root]$
以管理员身份执行命令 - sudo。
[hellokitty ~]$ ls /rootls: cannot open directory /root: Permission denied[hellokitty ~]$ sudo ls /root[sudo] password for hellokitty:
说明:如果希望用户能够以管理员身份执行命令,用户必须要出现在sudoers名单中,sudoers文件在
/etc目录下,如果希望直接编辑该文件也可以使用下面的命令。编辑sudoers文件 - visudo。
这里使用的编辑器是vi,关于vi的知识在后面有讲解。该文件的部分内容如下所示:
## Allow root to run any commands anywhereroot ALL=(ALL) ALL## Allows members of the 'sys' group to run networking, software,## service management apps and more.# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS## Allows people in group wheel to run all commands%wheel ALL=(ALL) ALL## Same thing without a password# %wheel ALL=(ALL) NOPASSWD: ALL## Allows members of the users group to mount and unmount the## cdrom as root# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom## Allows members of the users group to shutdown this system# %users localhost=/sbin/shutdown -h now
显示用户与用户组的信息 - id。
给其他用户发消息 -write / wall。
发送方:
[root ~]# write hellokittyDinner is on me.Call me at 6pm.
接收方:
[hellokitty ~]$Message from root on pts/0 at 17:41 ...Dinner is on me.Call me at 6pm.EOF
查看/设置是否接收其他用户发送的消息 - mesg。
[hellokitty ~]$ mesgis y[hellokitty ~]$ mesg n[hellokitty ~]$ mesgis n
