2. User-related commands

 

1. The user documentation

/etc/passwd User information file
/etc/shadow Shadow file
/etc/group Group information file
/etc/gshadow Group password file
  The user's home directory
/var/spool/mail/user1 The user's mailbox directory
/etc/skel/ User Template directory

/ Etc / passwd file the user information

root:x:0:0:root:/root:/bin/bash
第一列: 用户名
第二列: 密码位
第三列: 用户 ID
 0 超级用户 UID。如果用户 UID 为 0,代表这个账号是管理员账号。那 Linux 中
如何把普通用户升级成为管理员呢?就是把其他用户的 UID 修改为 0 就可以了,这点和
Windows 是不同的。不过不建议建立多个管理员账号。
 1-499 系统用户(伪用户) UID。这些 UID 账号是系统保留给系统用户的 UID,也就是
说 UID 是 1-499 范围内的用户是不能登录系统的,而是用来运行系统或服务的。其中
1-99 是系统保留的账号,系统自动创建。 100-499是预留给用户创建系统账号的。
 500-60000 普通用户 UID。建立的普通用户 UID 从 500 开始,最大到 60000。 这些用
户足够使用了,但是如果不够也不用害怕, 2.6.x 内核以后的 Linux 系统用户 UID 已经
可以支持 232这么多了。
第四列:组 ID GID 添加用户时,如果不指定用户所属的初始组,那么会建立和用户名相
同的组
第五列: 用户说明
第六列: 用户家目录 ~
第七列: 登录 shell /bin/bash

/ Etc / shadow shadow file

root:$6$9w5Td6lg$bgpsy3olsq9WwWvS5Sst2W3ZiJpuCGDY.4w4MRk3ob/i85fI38RH15wzVoomff9isV1Pzd
cXmixzhnMVhMxbv0:15775:0:99999:7:::
第一列: 用户名
更多云计算-Java –大数据 –前端 –python 人工智能资料下载,可百度访问:尚硅谷官网
云计算 Linux 课程系列
第二列: 加密密码
我们也可以在密码前人为的加入“!”或“*”改变加密值让密码暂时失效,使这个用
户无法登陆,达到暂时禁止用户登录的效果。
注意所有伪用户的密码都是“!!”或“*”,代表没有密码是不能登录的。当然我新
创建的用户如果不设定密码,它的密码项也是“!!”,代表这个用户没有密码,不能登录
第三列: 密码最近更改时间, 1970 年 1 月 1 日作为标准时间
第四列: 两次密码的修改间隔时间(和第 3 字段相比)
第五例: 密码有效期(和第 3 字段相比)
第六列: 密码修改到期前的警告天数(和第 5 字段相比)
第七列: 密码过期后的宽限天数(和第 5 字段相比)
第八列: 密码失效时间
这里同样要写时间戳,也就是用 1970 年 1 月 1 日进行时间换算。如果超过了
失效时间,就算密码没有过期,用户也就失效无法使用了
第九列: 保留

/ Etc / group file group information

root:x:0:root
第一列: 组名
第二列: 组密码位
第三列: GID
第四列: 此组中支持的其他用户.附加组是此组的用户
初始组:每个用户初始组只能有一个,初始组只能有一个,一般都是和用户名相同的组作为
初始组
附加组:每个用户可以属于多个附加组。要把用户加入组,都是加入附加组

2. User Management Commands
 

useradd 命令
useradd 用户名

设定密码
passwd [选项] 用户名
-l: 暂时锁定用户。仅 root 用户可用
-u: 解锁用户。仅 root 用户可用
--stdin: 可以将通过管道符输出的数据作为用户的密码。主要在批量添加用户时使用

echo "123" | passwd --stdin user1   //更改用户 user1 的密码 。

可以通过命令,把密码修改日期归零(shadow 第 3 字段) .这样用户一登陆就要修改密码,例如:
[root@localhost ~]# chage -d 0 user1

删除用户
userdel [-r] 用户名
-r: 在删除用户的同时删除用户的家目录

切换用户身份
su 命令可以切换成不同的用户身份,命令格式如下:
[root@localhost ~]# su [选项] 用户名
选项:
-: 选项只使用“-”代表连带用户的环境变量一起切换
-c 命令: 仅执行一次命令,而不切换用户身份
“-”不能省略,它代表切换用户身份时,用户的环境变量也要切换成新用户的环境变量。

Three sets of administrative commands

添加用户组
groupadd [选项] 组名
-g GID: 指定组ID

删除用户组: 
groupdel 组名

把用户添加进组或从组中删除:
 gpasswd
gpasswd [选项] 组名
-a 用户名: 把用户加入组
-d 用户名: 把用户从组中删除

Changing the effective Group: newgrp

Each user can belong to an initial set (the initial user is a user group), you can belong to a plurality of additional sets
(additional user is a user of this group). Since the user can belong to so many user groups, the user after creating the file, the default entry into force of
group identity which it? Of course, the group identity initial user group are effective, because once the initial group is a group of users to log on directly obtained
identity. In other words, after you create the user file, is a set of files is the user's initial group, because the effective user's default group is the initial group.
Since the user belongs to multiple groups of users, so users can not change the effective group do? Use newgrp command can switch the user has
the active set. Command format is as follows:
[the root @ localhost ~] # the newgrp group name
 

Guess you like

Origin blog.csdn.net/misxu890312/article/details/89221153