1、編寫腳本,接受二個(gè)位置參數(shù),magedu和/www,判斷系統(tǒng)是否有magedu,如果沒有則自動創(chuàng)建magedu用戶,并自動設(shè)置家目錄為/www
#!/bin/bash
grep "^$1" /etc/passwd &>/dev/null
if [ $? -eq 0 ];then
echo "$1 is existed."
else
useradd -d $2 $1
echo "$1 is created,home directory is $2."
fi
運(yùn)行結(jié)果:
[root@centos7 data]# bash userCheck.sh magedu /www
magedu is created,home directory is /www.
[root@centos7 data]# bash userCheck.sh magedu /www
magedu is existed.
2、使用expect實(shí)現(xiàn)自動登錄系統(tǒng)。
[root@centos7 data]# cat autoLogin.exp
#!/usr/bin/expect
set ip [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
interact
執(zhí)行結(jié)果:
[root@centos7 data]# expect autoLogin.exp 192.168.45.128 root qwe123
spawn ssh root@192.168.45.128
The authenticity of host '192.168.45.128 (192.168.45.128)' can't be established.
ECDSA key fingerprint is SHA256:IJSDPnogSYHD4HFYJdnm3q4DwUrEiMYNa71KRXUt69Q.
ECDSA key fingerprint is MD5:5d:c0:86:72:92:64:2d:09:b2:7e:33:ea:2b:35:71:75.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.45.128' (ECDSA) to the list of known hosts.
root@192.168.45.128's password:
Last login: Tue Jun 30 22:16:45 2020 from 192.168.45.200
3、簡述linux操作系統(tǒng)啟動流程

CentOS7啟動過程
第一階段:硬件引導(dǎo)
- 接通電源
- POST加電自檢
- 自檢通過后,選擇啟動介質(zhì)開始引導(dǎo)
- 加載MBR中的BootLoader:由于MBR只有512字節(jié),BootLoader占用前446個(gè)字節(jié),空間太小,所以BootLoader的啟動分為三個(gè)階段:
stage1:加載BootLoader的主程序,用于加載stage1.5的代碼;
stage1.5:位于MBR之后的扇區(qū),讓stage1中的BootLoader能夠識別stage2所在的分區(qū)文件系統(tǒng);
stage2:通過BootLoader加載所有的配置文件及相關(guān)參數(shù),這些參數(shù)都位于磁盤/boot/grub中
第二階段:GRUB2啟動引導(dǎo)階段
加載boot和core兩個(gè)鏡像,再加載mod模塊文件,把grub2程序加載執(zhí)行,接著解析配置文件/boot/grub/grub.cfg,根據(jù)配置文件加載內(nèi)核鏡像到內(nèi)存,之后構(gòu)建虛擬文件系統(tǒng),轉(zhuǎn)到內(nèi)核
第三階段:內(nèi)核引導(dǎo)階段
通過內(nèi)存中的虛擬根文件系統(tǒng),加載驅(qū)動,然后切換到真正的根文件系統(tǒng),并執(zhí)行初始化程序/usr/lib/systemd/systemd
第四階段:systemd初始化階段
執(zhí)行默認(rèn)target配置文件/etc/systemd/system/default.target,然后執(zhí)行sysinit.target來初始化系統(tǒng)和basic.target來準(zhǔn)備操作系統(tǒng),接著啟動multi-user.target下的本機(jī)與服務(wù)器服務(wù),并檢查/etc/rc.d/rc.local文件是否有用戶自定義腳本需要啟動,最后執(zhí)行multi-user下的getty.target及登陸服務(wù),檢查default.target是否有其他的服務(wù)需要啟動。
4、破解centos7 密碼。
第一步:在啟動界面按e進(jìn)入編輯模式
在啟動界面按e進(jìn)入編輯模式

在linux16開始的行,添加內(nèi)核參數(shù)rd.break

破解密碼操作,然后重啟即可