Linux使用vim创建用户

发布于 2020-09-27  259 次阅读


一.创建用户和组

/etc/passwd (用户)
/etc/group (用户组)
/etc/shadow (密钥文件)
/home/username (家目录)
/etc/skel/.* (骨架文件)

1.创建axb用户和fashi,shishou,tanke

使用vim编辑器编写/etc/passwd文件或者使用打印追加进文件

[root@localhost ~]# echo “axb:x:1983:9999:mygod:/axb:/bin/bash” >> /etc/passwd
[root@localhost ~]# echo "fashi:x:1984:8888:fashi:/chencan:/bin/bash" >> /etc/passwd
[root@localhost ~]# echo "sheshou:x:1985:8888:sheshou:/chencan1:/bin/bash" >> /etc/passwd
[root@localhost ~]# echo "tanke:x:1986:8888:tanke:/chencan2:/sbin/nologin" >> /etc/passwd
[root@localhost ~]# tail -4 /etc/passwd
axb:x:1983:9999:mygod:/axb:/bin/bash
fashi:x:1984:8888:fashi:/chencan:/bin/bash
sheshou:x:1985:8888:sheshou:/chencan1:/bin/bash
tanke:x:1986:8888:tanke:/chencan2:sbin/nologin

2.组

[root@localhost ~]# echo "mygod:x:9999:" >> /etc/group
[root@localhost ~]# echo "godjob:x:8888:fashi,axb,sheshou,tanke" >> /etc/group
[root@localhost ~]# id axb
uid=1983(axb) gid=9999(mygod) 组=9999(mygod),8888(godjob)
[root@localhost ~]# tail -5 /etc/group
postfix:x:89:
tcpdump:x:72:
chencan:x:1000:
mygod:x:9999:
godjob:x:8888:fashi,axb,sheshou,tanke

3.设置fashi为管理员

vim编辑/etc/gshadow文件

[root@localhost ~]# vim /etc/gshadow

二.设置用户目录

[root@localhost ~]# mkdir /axb
[root@localhost ~]# mkdir /fashi
[root@localhost ~]# mkdir /sheshou
[root@localhost ~]# mkdir /tanke

2.复制模板

[root@localhost ~]# cp /etc/skel/.* /axb
[root@localhost ~]# cp /etc/skel/.* /chencan
[root@localhost ~]# cp /etc/skel/.* /chencan1
[root@localhost ~]# cp /etc/skel/.* /chencan2

3.设置权限

[root@localhost ~]# chown axb:mygod /axb
[root@localhost ~]# chown fashi:godjob /chencan
[root@localhost ~]# chown sheshou:godjob /chencan1
[root@localhost ~]# chown tanke:godjob /chencan2

三.设置密码

加密命令:openssl passwd -1 {密码}

例如:openssl passwd -1 123  或 openssl passwd -1 ‘123’

1.生成加密密码

[root@localhost ~]# openssl passwd -1 'redhat'
$1$redhat$4ifR9BhPb9D70IbksJ8ZT0
[root@localhost ~]# openssl passwd -1 'moc.321'
$1$moc.321$GSjxDpVc5vh34/zeovdzR.

2.将加密密码写入到/etc/shado文件里

shado

四.验证

用户

用户

登录

登录


粉色的花瓣,美丽地缠绕在身上。依在风里。