一、要求:
手动添加用户user1, 设置其基本组为user1 (5000),附加组为othergroup,最后添加密码
二、操作过程:
1、创建用户组othergroup
[root@localhost home]# groupadd othergroup
2、添加用户组user1
[root@localhost home]# echo 'user1:x:5000' >> /etc/group
3、编辑/etc/group,修改用户组user1附加组为othergroup
[root@localhost home]# nano /etc/group
已修改记录为“othergroup:x:5001:user1”
4、验证/etc/group修改结果
[root@localhost home]# tail /etc/groupavahi-autoipd:x:101:gdm:x:42:sabayon:x:86:distro:x:3003:mandrivalinux:x:3004:fedora:x:2003:mandrivahbase:x:102:openstack:x:4005:othergroup:x:5001:user1user1:x:5000
5、向/etc/passwd中添加记录
[root@localhost home]# echo 'user1:x:5000:5000:User1:/home/user1:/bin/bash' >> /etc/passwd
6、验证/etc/passwd修改结果
[root@localhost home]# tail -1 /etc/passwduser1:x:5000:5000:User1:/home/user1:/bin/bash
7、向/etc/shadow中添加记录
[root@localhost home]# echo 'user1:!!:15995:0:99999:7:::' >> /etc/shadow
8、验证/etc/shadow修改结果
[root@localhost home]# tail -1 /etc/shadowuser1:!!:15995:0:99999:7:::
9、创建用户user1家目录,并修改其权限 (参考练习1)
[root@localhost home]# cp -r /etc/skel/ /home/user1[root@localhost home]# chown -R user1.user1 /home/user1[root@localhost home]# chmod -R go= /home/user1[root@localhost home]# ls -al /home/user1total 56drwx------ 3 user1 user1 4096 Oct 17 15:25 .drwxr-xr-x 6 root root 4096 Oct 17 15:25 ..-rw------- 1 user1 user1 33 Oct 17 15:25 .bash_logout-rw------- 1 user1 user1 176 Oct 17 15:25 .bash_profile-rw------- 1 user1 user1 124 Oct 17 15:25 .bashrc-rw------- 1 user1 user1 515 Oct 17 15:25 .emacsdrwx------ 4 user1 user1 4096 Oct 17 15:25 .mozilla[root@localhost home]# ls -dl /home/user1drwx------ 3 user1 user1 4096 Oct 17 15:25 /home/user1
10、生成MD5加密密码,密码为"redhat"
[root@localhost ~]# openssl passwd -1 -salt '12345678'Password:$1$12345678$0ME5N6oDyoEAwUp7b5UDM/
11、编辑/etc/shadow,将生成的密码添加进记录中,替换第二个字段'!!'
[root@localhost home]# nano /etc/shadow
12、使用user1用户登陆系统,能正常登陆即表示添加用户操作成功。