Linux第二周作业
目录
题目
解题
1)
2)
3)
4)
5)
6)
题目
1、查看/etc/passwd文件的第18-20行内容,并将找到的内容存储至/home/passwd文件中(head,tail,>,>>)
2、查找/etc/passwd文件中包含root字符的行并将找到的行存储至/root/passwd文件中(grep,>,>>)
3、将/home目录复制到/root目录(cp -r)
4、将/root/home目录,/home/passwd和/root/passwd打包并压缩为/root/hp.tar.xz(tar -cJf)
5、创建组admin-group,添加用户admin属于admin-group组(groupadd,useradd -g -G)
6、为admin账号设置密码为123(passwd)
解题
1)
[root@HeHe ~]# head -20 /etc/passwd | tail -2 > ../home/passwd
[root@HeHe ~]# cat ../home/passwd
colord:x:997:995:User for colord:/var/lib/colord:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
2)
[root@HeHe ~]# grep root /etc/passwd > ./passwd
[root@HeHe ~]# cat passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
3)
[root@HeHe ~]# cp -r ../home ./
[root@HeHe ~]# tree home
home
├── dir1
├── file1
├── lihua
├── passwd
├── pasSWD
├── Passwd
├── PASSWD
├── passwd_copy
└── redhat1├── Desktop├── Documents├── Downloads├── Music├── Pictures├── Public├── Templates└── Videos12 directories, 5 files
4)
[root@HeHe ~]# tar cJf ./hp.tar.xz ./home ../home/passwd ./passwd
tar: Removing leading `../' from member names
tar: Removing leading `../' from hard link targets
#这个警告是因为每个电脑的环境不一样,避免其他设备解压时修改其/etc下的passwd导致系统损坏
[root@HeHe ~]# tar tf hp.tar.xz
./home/
./home/redhat1/
./home/redhat1/.bash_logout
--
home/passwd
./passwd
5)
[root@HeHe ~]# groupadd admin-group
[root@HeHe ~]# useradd -g admin-group admin
[root@HeHe ~]# tail -1 /etc/passwd
admin:x:7879:7879::/home/admin:/bin/bash
[root@HeHe ~]# tail -1 /etc/group
admin-group:x:7879:
#不看组id的话
[root@HeHe ~]# groups admin
admin : admin-group
6)
[root@HeHe ~]# passwd admin
Changing password for user admin.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@HeHe ~]# tail -1 /etc/shadow
admin:$6$HmphXxUW7qCulRXL$kwSPeholk5EcImA/I.uRagLhie.cf/2FyP15CV0EAnd6zugboPLi/ZCEWnAJC8SfV4xNWeRAz0/pW3uSCDmID0:20030:0:99999:7:::