linux⽤户的秘密之login.defs⽂件详解
我们都知道linux下有很多⽤户,有超级管理员⽤户,有普通⽤户,还有很多的系统⽤户。
那么问题来了,这些⽤户是怎样产⽣的呢?⼜是那些规则决定着这些⽤户的属性呢?那么,就让我带你们⾛进linux,揭开它的神秘⾯纱吧!
凡是接触过linux的⼈都知道,创建⼀个⽤户只需要很简单的⼀个命令:“useradd +⽤户名”就能成功创建⼀个linux普通⽤
户,“passwd +⽤户名”就可以给⽤户设定密码。
[root@tomcatClient ~]# useradd liupengfang
[root@tomcatClient ~]# passwd liupengfang
更改⽤户 liupengfang 的密码 。
新的 密码:
重新输⼊新的 密码:
passwd: 所有的⾝份验证令牌已经成功更新。
创建完成后,我们可以⽤id命令查看该⽤户的ID:
[root@tomcatClient ~]# id liupengfang
uid=4005(liupengfang) gid=4005(liupengfang) 组=4005(liupengfang)
还可以在/home⽬录下查看到该⽤户的家⽬录:
[root@tomcatClient ~]# cd /home/
[root@tomcatClient home]# ls
fedora  Fedora  liupengfang  mandriva
我们会看到⽤户liupengfang的uid为4005,gid也为4005.为什么这些id不是从1开始呢?为什么在创建该⽤户后会在/home⽬录下创建⼀个⾃⼰的家⽬录呢?这些⽤户会不会过期呢?这就需要我们了解⼀个⽂件------login.defs。
我们查看下这个⽂件:
[root@tomcatClient home]# vim /etc/login.defs
PASS_MAX_DAYS  99999    #密码最长过期时间
PASS_MIN_DAYS  0        #密码最短过期时间
PASS_MIN_LEN    5        #密码最⼩长度
PASS_WARN_AGE  7        #密码过期提前提醒时间
#
# Min/max values for automatic uid selection in useradd
#
UID_MIN                  500    #uid最⼩值
UID_MAX                60000    #uid最⼤值
#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN                  500    #gid最⼩值
GID_MAX                60000    #gid最⼩值
#
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD    /usr/sbin/userdel_local
#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag o
n
# useradd command line.
#
CREATE_HOME    yes    #是否同时建⽴家⽬录
# The permission mask is initialized to this value. If not specified
linux创建新用户和密码,
# the permission mask will be initialized to 022.
UMASK          077    #创建后⽤户的权限掩码
# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes    #创建⽤户时是否同时创建相同⽤户名的组
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512    #密码加密⽅式为SHA512
看完这个配置⽂件,我们就会⼤致了解,为什么⽤户创建后它的那些属性其实都是有根有据的,login.defs这个⽂件就是⽤来设置⽤户创建时属性的⽂件。当然这些属性也不是固定不变的,我们可以⽤usermod +参数来改变它的各个属性,⽽这些参数只要man⼀下就知道了。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。