1衡创、編寫腳本运悲,接受二個(gè)位置參數(shù)婉商,magedu和/www似忧,判斷系統(tǒng)是否有magedu,如果沒(méi)有則自動(dòng)創(chuàng)建magedu用戶丈秩,并自動(dòng)設(shè)置家目錄為/www
#!/bin/bash
user=$1
dir=$2
colorB="\033[1;33m"
colorE="\033[0m"
password=`mkpasswd -l 10 -d 3`
if [ ! -d $dir ];then
? ????mkdir -p $dir
fi
getent passwd|grep $user &> /dev/null
if [ `echo $?` -eq 0 ];then
? ???? echo "$user user is exists"
? ???? usermod -d $dir $user
? ???? echo "$password"|passwd --stdin $user| passwd -e $user $> /dev/null
? ???? echo -e "$colorB$user$colorE home directory change to $colorB$dir$colorE,password the change to $colorB$password$colorE,Please login to change the password"
else
????? useradd $user -d $dir
? ???? echo "$password"| passwd --stdin $user|passwd -e $user &> /dev/null
? ???? echo -e "$colorB$user$colorE user is created!! $colorB$user$colorE home directory is $colorB$dir$colorE,password is $colorB$password$colorE,Please login to change the password"
fi
2盯捌、使用expect實(shí)現(xiàn)自動(dòng)登錄系統(tǒng)。
#!/usr/bin/expect
set ip 192.168.2.240
set user root
set password xxxxxxxxx
set timeout 5
spawn ssh $user@$ip
expect {
? ? "yes/no" {send "yes\n";exp_continue}
? ? "password" {send "$password\n"}
}
interact
expect eof
#!/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
expect eof
3蘑秽、簡(jiǎn)述linux操作系統(tǒng)啟動(dòng)流程?
? ? ? ? centos6系統(tǒng)啟動(dòng)流程
? ? ? ? 1)物理主機(jī)加電饺著,主板通電后,CPU開始工作肠牲,它執(zhí)行國(guó)定地址處的一段很小的硬編碼程序:BIOS幼衰,于是BIOS獲取CPU的控制權(quán)。
????????2)讀取第一個(gè)啟動(dòng)設(shè)備MBR的引導(dǎo)加載程序(grub)的啟動(dòng)信息
????????3)加載核心操作系統(tǒng)的核心信息缀雳,核心開始解壓縮渡嚣,并嘗試驅(qū)動(dòng)所有的硬件設(shè)備
????????4)核心執(zhí)行init程序,并獲取默認(rèn)的運(yùn)行信息
????????5)init程序執(zhí)行/etc/rc.d/rc.sysinit文件
? ? ? ? 6)啟動(dòng)核心的外掛模塊
????????7)init執(zhí)行運(yùn)行的各個(gè)批處理文件(scripts)
????????8)init執(zhí)行/etc/rc.d/rc.local
????????9)執(zhí)行/bin/login程序,等待用戶登錄
????????10)登錄之后開始以Shell控制主機(jī)
4严拒、破解centos7?密碼扬绪。
? ? 1)啟動(dòng)系統(tǒng),在grub提供菜單的界面下裤唠,在對(duì)應(yīng)菜單項(xiàng)下按鍵盤的e鍵,進(jìn)入編輯模式莹痢。
? ? 2)通過(guò)箭頭方向鍵移動(dòng)光標(biāo)到linux16這一行种蘸,在這行的末尾處加上rd.break,然后按ctrl+x引導(dǎo)系統(tǒng)竞膳。
? ? 3)當(dāng)前根被掛載到/sysroot目錄下航瞭,并且是只讀掛載,需要重新掛載為讀寫模式坦辟,然后使用chroot切到系統(tǒng)原來(lái)的根目錄下修改密碼刊侯。
? ? 4)執(zhí)行兩次exit退出重啟系統(tǒng),使用新密碼登錄系統(tǒng)驗(yàn)證锉走。