useradd配置文件详解

/etc/default/useradd文件 useradd命令的配置文件
默认shell就是/bin/bash
为什么默认的家目录在home下
为什么默认的家目录/home/用户名下面有很多隐藏文件,从哪来的。

就是/etc/default/useradd文件配置的。

[root@oldboyedu ~]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

修改方法:
useradd -D -s /bin/sh 相当于vim编辑/etc/default/useradd文件。
[root@oldboyedu ~]# useradd -D -s /bin/sh
[root@oldboyedu ~]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

[root@oldboyedu ~]# useradd chenglong1
You have new mail in /var/spool/mail/root
[root@oldboyedu ~]# tail -1 /etc/passwd
chenglong1:x:1007:1009::/home/chenglong1:/bin/sh
[root@oldboyedu ~]# chage -l chenglong1
Last password change : Mar 25, 2019
Password expires : never
Password inactive : never
Account expires : Oct 21, 2020
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7


/etc/skel目录,创建用户默认就会把此目录下的文件拷贝到/home/用户名下。
/etc/skel 为每个用户提供用户环境变量的目录。
[root@oldboyedu ~]# ls /etc/skel -A
.bash_logout .bash_profile .bashrc
===================================================
.bash_logout .bash_profile .bashrc 用户环境变量

登录系统后,命令行出现如下提示:为什么?
[root@oldboyedu /home/chenglong1]# su - chenglong1
-sh-4.2$
-sh-4.2$
解答:用户的环境变量缺失导致的。
执行如下命令解决
-sh-4.2$ cp /etc/skel/.bash* .
-sh-4.2$ source ./.bash_profile ./.bashrc
[chenglong1@oldboyedu ~]$
[chenglong1@oldboyedu ~]$

-sh-4.2$ export PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \w\[\e[0m\]]\$'
[chenglong1@oldboyedu ~]$

添加用户要用的文件
/etc/login.defs 了解

添加用户要用的文件
/etc/login.defs /etc/skel /etc/default/useradd


编辑/etc/passwd,通过注释来删除。
#chenglong1:x:1007:1009::/home/chenglong1:/bin/sh
"/etc/passwd" 30L, 1362C written
[root@oldboyedu ~]# su - chenglong1
su: user chenglong1 does not exist


[root@oldboyedu ~]# useradd -u 9999 -s /bin/sh -M -g sa -c "老男孩" -e "2019/5/1" zongsheng
[root@oldboyedu ~]# tail -1 /etc/passwd
zongsheng:x:9999:1003:老男孩:/home/zongsheng:/bin/sh
[root@oldboyedu ~]# id zongsheng
uid=9999(zongsheng) gid=1003(sa) groups=1003(sa)
[root@oldboyedu ~]# chage -l zongsheng
Last password change : Mar 25, 2019
Password expires : never
Password inactive : never
Account expires : May 01, 2019
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7

usermod -u 8888 -s /bin/bash -m /home/zongsheng -g incahome -c "男孩" -e "2020/5/1"
[root@oldboyedu ~]# usermod -u 8888 -s /bin/bash -g incahome -c "男孩" -e "2020/5/1" zongsheng
[root@oldboyedu ~]# chage -l zongsheng
Last password change : Mar 25, 2019
Password expires : never
Password inactive : never
Account expires : May 01, 2020
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@oldboyedu ~]# id zongsheng
uid=8888(zongsheng) gid=1004(incahome) groups=1004(incahome)
[root@oldboyedu ~]# tail -1 /etc/passwd
zongsheng:x:8888:1004:男孩:/home/zongsheng:/bin/bash
You have new mail in /var/spool/mail/root

usermod -u 8888 -s /bin/bash -g incahome -c "男孩" -e "2020/5/1" zongsheng
usermod -m /home/zongsheng zongsheng

不交互设置密码:
方法1:
[root@oldboyedu ~]# echo 123456|passwd --stdin oldgirl
Changing password for user oldgirl.
passwd: all authentication tokens updated successfully.

方法2:
[root@oldboyedu ~]# echo 123456 >pass
[root@oldboyedu ~]# cat pass
123456
[root@oldboyedu ~]# passwd --stdin oldgirl <pass
Changing password for user oldgirl.
passwd: all authentication tokens updated successfully.


[root@oldboyedu ~]# tail -4 /etc/passwd|awk -F ":" '{print $1":oldboy"}' >user.log
[root@oldboyedu ~]# cat user.log
gongli1:oldboy
gongli2:oldboy
chenglong1:oldboy
zongsheng:oldboy

chpasswd对密码文件的要求是上述user.log

方法1:
[root@oldboyedu ~]# chpasswd<user.log
方法2:
[root@oldboyedu ~]# tail -4 /etc/passwd|awk -F ":" '{print $1":oldboy"}'|chpasswd

posted @ 2020-01-14 20:07  陶清刚  阅读(124)  评论(0编辑  收藏  举报