第九周作業

1、編寫腳本,接受二個位置參數,magedu和/www,判斷系統是否有magedu,如果沒有則自動創建magedu用戶,並自動設置家目錄爲/www

[root@centos6 ~]#cat usermagedu.sh
#!/bin/bash
#接受二個位置參數,magedu和/www,判斷系統是否有magedu,如果沒有則自動創建magedu用戶,並自動設置家目錄爲/www
id $1 &>/devnull
if [ $? -eq 0 ];then
    echo 用戶$1 已存在!
else
    useradd -d $2 $1 && echo "用戶$1 已創建,家目錄爲$2 !"
fi

[root@centos6 ~]#bash usermagedu.sh root
用戶root 已存在!
[root@centos6 ~]#bash usermagedu.sh magedu /www
用戶magedu 已創建,家目錄爲/www !
[root@centos6 ~]#bash usermagedu.sh magedu /www
用戶magedu 已存在!
[root@centos6 ~]#id magedu
uid=2005(magedu) gid=2005(magedu) groups=2005(magedu)
[root@centos6 ~]#tail -1 /etc/passwd
magedu:x:2005:2005::/www:/bin/bash

2、使用expect實現自動登錄系統。

先看下系統有沒expect命令,沒有的話yum安裝一下
先寫個expect腳本

[root@centos6 ~]#cat expect.sh 
#!/usr/bin/expect
spawn ssh 192.168.36.71
expect {
    "yes/no" { send "yes\n";exp_continue }
    "password" { send "123123\n" }
}
interact
#expect eof

執行腳本

[root@centos6 ~]#expect expect.sh 
spawn ssh 192.168.36.71
[email protected]'s password: 
Last login: Sat Mar 28 17:32:02 2020 from 192.168.36.1

已經在目標機器上了

[root@centos7 ~]#ip a
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:a3:3f:e1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.36.71/24 brd 192.168.36.255 scope global noprefixroute ens33
[root@centos7 ~]#exit
logout
Connection to 192.168.36.71 closed.
[root@centos6 ~]#

可以登錄目標及機器操作,也可以不登錄執行需要的命令後返回


3、簡述linux操作系統啓動流程

第九周作業


4、破解centos7 密碼。

破解CentOS7的root口令方法一
啓動時任意鍵暫停啓動
第九周作業
按e鍵進入編輯模式
第九周作業
將光標移動linux16開始的行,添加內核參數rd.break
第九周作業
按ctrl-x啓動
第九周作業
mount –o remount,rw /sysroot (掛載)
第九周作業
chroot /sysroot(切換根目錄)
第九周作業
passwd root(重設密碼)
第九周作業
touch /.autorelabel(有這個文件存在,系統在重啓時就會對整個文件系統進行relabeling重新標記,也可以理解爲對文件進行底層權限的控制和標記)
exit
reboot
第九周作業
已經可以登錄了
第九周作業
破解CentOS7的root口令方法二
啓動時任意鍵暫停啓動
按e鍵進入編輯模式
將光標移動linux16開始的行,改爲rw init=/sysroot/bin/sh
按ctrl-x啓動
chroot /sysroot
passwd root
touch /.autorelabel
exit
reboot

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章