写在前面:
包含了个人运行时出现的一些错误和改正
一些参考:Linux报错总结
1.创建用户student2,uid为6666,密码为2,然后删除时,忘记使用-r,现在要求把残留的文件找出并删除。
//全部过程及错误解析
//创建用户student2 uid为6666
[root@localhost ~]# useradd student2 -u 6666
useradd: user 'student2' already exists
//提示我student2已经存在 使用cat命令查看是否存在
[root@localhost ~]# cat /etc/group
root:x:0:
wheel:x:10:teacher1,qq,tt
student1:x:6666:
qq:x:6668:
tt:x:6669:
//虽然不存在但是还是使用一下-r删除吧
[root@localhost ~]# userdel -r student2
[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
wheel:x:10:teacher1,qq,tt
student1:x:6666:
qq:x:6668:
tt:x:6669:
//添加student2 想起来我的student1就是6666 没办法一样
//那咋整捏 student1多可爱啊 为什么要换student1捏 我把student2的uid改成6667老师应该不会打我吧()
[root@localhost ~]# useradd student2 -u 6666
useradd: UID 6666 is not unique
//创建用户student2 uid为6667
[root@localhost ~]# useradd student2 -u 6667
//查看
[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
student1:x:6666:
qq:x:6668:
tt:x:6669:
student2:x:6667:
//真是……
[root@localhost ~]# echo "2" | passwd -- stdin student2
passwd: Only one user name may be specified.
[root@localhost ~]# echo "2" |passwd -- stdin student2
passwd: Only one user name may be specified.
[root@localhost ~]# echo "2"|passwd -- stdin student2
passwd: Only one user name may be specified.
//看到这里我觉得student2已经有密码了 也懒得再用passwd student2加密码了
//记得有个可以查看passwd的命令 我找找
[root@localhost ~]# passwd student2
Changing password for user student2.
New password:
BAD PASSWORD: No password supplied
Retype new password:
No password supplied
//查看密码 发现看不到密码 密码被用x替代了 开始百度
[root@localhost ~]# cat /etc/passwd
student1:x:6666:6666::/home/student1:/bin/bash
qq:x:6668:6668::/home/qq:/bin/bash
tt:x:6669:6669::/home/tt:/bin/bash
student2:x:6667:6667::/home/student2:/bin/bash
//百度发现用cat /etc/shadow 可以实现
//结果发现还是加密密码(悲)
[root@localhost ~]# cat /etc/shadow
mika:$1$kgGPrGgC$F8207UwHzryNS0WqYk0B80:19047:0:99999:7:::
student1:$6$u4MT0vZzQ2zqqnQX$OYJyY3NlANHvChS4tJbquw33T2tajLiYUXnLhTQTawuyCWwlxr1QTjF7stnmYZP7oqgZHIU6sSXenxY3un92n1:19061:0:99999:7:::
qq:$6$pdXzjQ0KJEMQtc.M$5GwhvlHoJlFTMaIJ6h0lexRMFIKiwUTqAryW8HwzalP8bTE8B5k4BG8PjsmIwe0.8C1ZFPgOFIC2RTalj3sg51:19066:0:99999:7:::
tt:!!:19066:0:99999:7:::
student2:!!:19066:0:99999:7:::
//开始进行删除操作
//删除前
[root@localhost ~]# cd /home
[root@localhost home]# ll
total 4
drwx------. 15 mika mika 4096 Feb 24 14:53 mika
drwx------. 4 qq qq 113 Mar 15 10:30 qq
drwx------. 3 student1 student1 78 Mar 10 10:25 student1
drwx------. 3 student2 student2 78 Mar 15 11:25 student2
drwx------. 5 test test 114 Mar 15 10:55 test
drwx------. 3 tt tt 78 Mar 15 10:32 tt
//不加r删除
[root@localhost home]# userdel student2
//查看家目录邮箱目录之类是否删除(并没有)
[root@localhost home]# ll
total 4
drwx------. 15 mika mika 4096 Feb 24 14:53 mika
drwx------. 4 qq qq 113 Mar 15 10:30 qq
drwx------. 3 student1 student1 78 Mar 10 10:25 student1
drwx------. 3 6667 6667 78 Mar 15 11:25 student2
drwx------. 5 test test 114 Mar 15 10:55 test
drwx------. 3 tt tt 78 Mar 15 10:32 tt
//查看组用户是否删除(被删除了)
[root@localhost home]# cat /etc/group
root:x:0:
student1:x:6666:
qq:x:6668:
tt:x:6669:
//找出残留的文件并删除
[root@localhost home]# useradd student2 -u 6667
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
[root@localhost home]# ll
total 4
drwx------. 15 mika mika 4096 Feb 24 14:53 mika
drwx------. 4 qq qq 113 Mar 15 10:30 qq
drwx------. 3 student1 student1 78 Mar 10 10:25 student1
drwx------. 3 student2 student2 78 Mar 15 11:25 student2
drwx------. 5 test test 114 Mar 15 10:55 test
drwx------. 3 tt tt 78 Mar 15 10:32 tt
[root@localhost home]# cat /etc/group
root:x:0:
student1:x:6666:
qq:x:6668:
tt:x:6669:
student2:x:6667:
[root@localhost home]# find / -uid 6667
find: ‘/proc/18298/task/18298/fd/5’: No such file or directory
find: ‘/proc/18298/task/18298/fdinfo/5’: No such file or directory
find: ‘/proc/18298/fd/6’: No such file or directory
find: ‘/proc/18298/fdinfo/6’: No such file or directory
find: ‘/run/user/1001/gvfs’: Permission denied
/var/spool/mail/student2
^Z
[1]+ Stopped find / -uid 6667
//这里我在想如果不新建student2是否可以查找到
//试试 先保存个快照
//说干就干~
[root@localhost home]# userdel student2
userdel: user 'student2' does not exist
[root@localhost home]# find / -uid 6667
find: ‘/proc/18432/task/18432/fd/5’: No such file or directory
find: ‘/proc/18432/task/18432/fdinfo/5’: No such file or directory
find: ‘/proc/18432/fd/6’: No such file or directory
find: ‘/proc/18432/fdinfo/6’: No such file or directory
find: ‘/run/user/1001/gvfs’: Permission denied
/var/spool/mail/student2
/home/student2
/home/student2/.mozilla
/home/student2/.mozilla/extensions
/home/student2/.mozilla/plugins
/home/student2/.bash_logout
/home/student2/.bash_profile
/home/student2/.bashrc
//经典删不掉 我也忘了为什么删不掉 不过老师不看结果就没事
[root@localhost home]# find/ -uid 6667 -exec rm -rd {} \;
-bash: find/: No such file or directory
//如果上述成功这是方法2 如果不成功这也是方法2
[root@localhost home]# useradd student2 -u 6667
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
[root@localhost home]# userdel -r student2
[root@localhost home]# ll
total 4
drwx------. 15 mika mika 4096 Feb 24 14:53 mika
drwx------. 4 qq qq 113 Mar 15 10:30 qq
drwx------. 3 student1 student1 78 Mar 10 10:25 student1
drwx------. 5 test test 114 Mar 15 10:55 test
drwx------. 3 tt tt 78 Mar 15 10:32 tt
[root@localhost home]#
//答案纯享版本
[root@localhost ~]# useradd student2 -u 6666
[root@localhost ~]# echo "2" | passwd -- stdin student2
[root@localhost home]# userdel student2
[root@localhost home]# find / -uid 6666 (这一步可以不要)
[root@localhost home]# find/ -uid 6666 -exec rm -rd {} \;
(或者替换最后一步为)
[root@localhost home]# useradd student2 -u 6666
[root@localhost home]# userdel -r student2
2.创建用户teacher3,该用户无法以交互的方式登录终端。然后尝试使用su - 命令切换到词用户,如果失败,那么改为可登录的方式。密码为1,切换到teacher3用户,要求在此用户下,创建用户teacher4。
//切换
[root@localhost home]# su -
Last login: Tue Mar 15 11:16:01 CST 2022 on pts/0
//创建用户teacher3
//这里不知道为什么 可能是我开的程序太多它比较卡
//事实上还是运行成功了
[root@localhost ~]# useradd -s /sbin/nologin teacher3
The memcache was not invalidated by NSS responder.
[root@localhost ~]# useradd -s /sbin/nologin teacher3
useradd: user 'teacher3' already exists
//这里我最开始没有读懂它什么意思 后来才发现需要用的是禁止用户交互
[root@localhost ~]# su - teacher3
[teacher3@localhost ~]$ exit
logout
//这里我比较偷懒懒得找权限 用的是加到管理员组中更改权限
[root@localhost ~]# vim /etc/group
[root@localhost ~]# cat /etc/group
root:x:0:
wheel:x:10:teacher1,qq,tt,teacher3
student1:x:6666:
qq:x:6668:
tt:x:6669:
teacher3:x:6670:
//更改完权限了 切换用户
[root@localhost ~]# su - teacher3
Last login: Tue Mar 15 14:37:34 CST 2022 on pts/0
//视图创建用户
[teacher3@localhost ~]$ useradd teacher4
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
//好像不行
//想起来密码还没设置 切出去设置密码
[teacher3@localhost ~]$ exit
logout
[root@localhost ~]# passwd teacher3
Changing password for user teacher3.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
//再次登录
[root@localhost ~]# su - teacher3
Last login: Tue Mar 15 14:40:13 CST 2022 on pts/0
//使用sudo命令
[teacher3@localhost ~]$ sudo useradd teacher4
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for teacher3:
The memcache was not invalidated by NSS responder.
[teacher3@localhost ~]$ exit
logout
//成功
[root@localhost ~]# cat /etc/group
root:x:0:
wheel:x:10:teacher1,qq,tt,teacher3
mika:x:1001:
student1:x:6666:
qq:x:6668:
tt:x:6669:
teacher3:x:6670:
teacher4:x:6671:
//方法2 顺便把1做的删了
//删除上面给的权限
[root@localhost ~]# vim /etc/group
//更改
[root@localhost ~]# visudo
//想起来teacher4还没删 不好测试
[root@localhost ~]# su - teacher3
Last login: Tue Mar 15 14:41:27 CST 2022 on pts/0
[teacher3@localhost ~]$ exit
logout
//删了teacher4
[root@localhost ~]# userdel -r teacher4
The memcache was not invalidated by NSS responder.
[root@localhost ~]# userdel -r teacher4
userdel: user 'teacher4' does not exist
//登录teacher3
[root@localhost ~]# su - teacher3
Last login: Tue Mar 15 14:55:25 CST 2022 on pts/0
//使用sudo命令创建
[teacher3@localhost ~]$ sudo useradd teacher4
[sudo] password for teacher3:
The memcache was not invalidated by NSS responder.
//验证
[teacher3@localhost ~]$ exit
logout
[root@localhost ~]# cat /etc/group
root:x:0:
bin:x:1:
wheel:x:10:teacher1,qq,tt
test:x:1000:
mika:x:1001:
student1:x:6666:
qq:x:6668:
tt:x:6669:
teacher3:x:6670:
teacher4:x:6671:
[root@localhost ~]#
//答案纯享版本
//我的错误是审题不严 它有一步“可登录的方式” 被我忽略了
[root@localhost ~]# useradd -s /sbin/nologin teacher3
[root@localhost ~]# echo "1" | passwd -- stdin teacher3
[root@localhost ~]# su - teacher3
[teacher3@localhost ~]$ exit
[root@localhost ~]# vim /etc/group
[root@localhost ~]# cat /etc/group
[root@localhost ~]# su - teacher3
[teacher3@localhost ~]$ sudo useradd teacher4
[teacher3@localhost ~]$ exit
[root@localhost ~]# cat /etc/group
(或者是)
[root@localhost ~]# useradd -s /sbin/nologin teacher3
[root@localhost ~]# echo "1" | passwd -- stdin teacher3
[root@localhost ~]# su - teacher3
[teacher3@localhost ~]$ exit
[root@localhost ~]# visudo
[root@localhost ~]# su - teacher3
[teacher3@localhost ~]$ sudo useradd teacher4
[teacher3@localhost ~]$ exit
[root@localhost ~]# cat /etc/group
3.查找/etc/passwod中含有root字段的行,保存到/root/目录的root.txt中
//先查看有没有root.txt文件
[root@localhost ~]# vim root.txt
//查找含有字段的行并保存
[root@localhost ~]# cat /etc/passwd | grep "root">/root/root.txt
[root@localhost ~]# vim root.txt