九、Linux系统启动管理与密码破解
作者:互联网
1.编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu用户,并自动设置家目录为/www。
[root@localhost /data]#./createusertest.sh
Please Input 2 Args,Usage:./createusertest.sh magedu /www.
[root@localhost /data]#./createusertest.sh magedu /www
The User magedu is created.
[root@localhost /data]#cat /etc/passwd |grep magedu
magedu:x:2013:2013::/www:/bin/bash
[root@localhost /data]#./createusertest.sh magedu /www
Error,The User magedu maybe existed,Check it.
[root@localhost /data]#cat createusertest.sh
#!/bin/bash
#********************************************************************
#Author: Kevin.Wen
#Revision: 1.0
#QQ: 2510905014
#Date: 2020-11-10
#FileName: createusertest.sh
#********************************************************************
if [ $# != 2 ];then
echo "Please Input 2 Args,Usage:./createusertest.sh magedu /www."
exit
fi
id $1 &> /dev/null
if [ $? != 0 ];then
useradd $1 -d $2
echo "The User $1 is created."
else
echo "Error,The User $1 maybe existed,Check it."
fi
2.使用expect实现自动登录系统。
[root@localhost /data]#./ssh.sh
spawn ssh root@10.0.0.111
The authenticity of host '10.0.0.111 (10.0.0.111)' can't be established.
ECDSA key fingerprint is SHA256:kAt7IKd1y+BNs+aq6c7ZGPJSN0yJ1RDTwqIYfB4KZV8.
ECDSA key fingerprint is MD5:c2:0f:f6:82:fb:0d:83:69:c5:ae:cd:6c:0b:9f:48:ce.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.111' (ECDSA) to the list of known hosts.
root@10.0.0.111's password:
Last login: Tue Nov 10 11:37:16 2020 from 10.50.100.12
[root@localhost ~]# exit
logout
Connection to 10.0.0.111 closed.
[root@localhost /data]#cat ssh.sh
#!/usr/bin/expect
#********************************************************************
#Author: Kevin.Wen
#Revision: 1.0
#QQ: 2510905014
#Date: 2020-11-10
#FileName: ssh.sh
#********************************************************************
set timeout 3
set PASS "123456"
spawn ssh root@10.0.0.111
expect {
"yes/no" { send "yes\n";exp_continue }
"password:" { send "$PASS\n";exp_continue }
}
interact
3.简述linux操作系统启动流程.
/sbin/init --> (/etc/inittab) --> 设置默认运行级别 --> 运行系统初始脚本/etc/rc.d/rc.sysinit、完成系统初始化 --> (关闭对应下需要关闭的服务)启动需要启动服务/etc/rc#.d/Sxxxx,/etc/rc.d/rc.local--> 设置登录终端
4.破解centos7 密码。
启动时任意键暂停启动
按e键进入编辑模式
将光标移动linux 开始的行,添加内核参数rd.break
按ctrl-x启动
mount –o remount,rw /sysroot
chroot /sysroot
passwd root
#如果SELinux是启用的,才需要执行下面操作,如查没有启动,不需要执行
touch /.autorelabel
exit
reboot
标签:10.0,www,系统启动,magedu,sh,Linux,root,破解,localhost 来源: https://www.cnblogs.com/studywen/p/13786601.html