基础篇--用户管理

直接命令开始

/etc/passwd:用户信息文件

/etc/shadow:查看用户密码文件

/etc/group:组信息文件

/etc/gshadow:组密码文件

echo $HOME:用户家目录

echo $PATH:用户shell目录

id:显示用户信息

passwd:修改用户密码

[root@localhost ~]# head -n 3 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@localhost ~]# head -n 3 /etc/shadow
root:$6$s8x1Sj7r$Hi1TJbCG.jKn.FUdHvmDr3iwUeNkDehDo1ivbcffXG.PaXNHRb3fDzgw86PRS00cltaZwMmB/nNroO2sH9Aeu.:16584:0:99999:7:::
bin:*:16141:0:99999:7:::
daemon:*:16141:0:99999:7:::
[root@localhost ~]# head -n 3 /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
[root@localhost ~]# head -n 3 /etc/gshadow
root:::
bin:::
daemon:::
[root@localhost ~]# id root
uid=0(root) gid=0(root) groups=0(root)

usermod:修改用户的属性

[root@localhost ~]# usermod 
Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account  家目录
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group  gid的值
  -G, --groups GROUPS           new list of supplementary GROUPS   所属组
  -a, --append                  append the user to the supplemental GROUPS   添加组
                                mentioned by the -G option without removing
                                him/her from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name  
  -L, --lock                    lock the user account  锁定用户
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             new login shell for the user account   shell程序
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account  解锁用户
  -Z, --selinux-user SEUSER     new SELinux user mapping for the user account

userdel:删除命令(特别需要注意,删除的时候跟上-r参数)

useradd:添加用户(大家自己看help文档,大同小异)

groupadd:添加组(大家自己看help文档)

groupdel:删除组

groupmod:修改组属性

管理用户的密码:chage

chage -m 0 -M 90 -W 7 -I 14 username

chage -d 0 username:强制下一次启动修改密码

chage -l username:列出当前用户的设置

chage -E YYYY-MM-DD:修改时间

[root@localhost ~]# chage -M 90 stu
[root@localhost ~]# chage -l stu
Last password change                    : May 22, 2015
Password expires                    : Aug 20, 2015
Password inactive                    : never
Account expires                        : never
Minimum number of days between password change        : 0
Maximum number of days between password change        : 90
Number of days of warning before password expires    : 7
原文地址:https://www.cnblogs.com/BloodZero/p/4539313.html