作业九(2020-08-09)

1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu用户,并自动设置家目录为/www

方法一:

#!/bin/bash

if [ "$1" == "magedu" -a "$2" == "/www" ];then

        if id $1 &> /dev/null;then

                echo $1 existed

        else

                useradd -d $2 $1 > /dev/null

                { echo 123456 > passwd --stdin $1;echo $1 is created;echo user is $1 homedir is $2; }

        fi

else

        echo please input magedu and /www

fi

方法二:

#!/bin/bash

[ "$1" == "magedu" -a "$2" == "/www" ] || { echo pleae input magedu and /www;exit 1; }

id $1 &> /dev/null && echo $1 is existed || { useradd -d $2 $1;echo 123456 > passwd --stdin $1;echo $1 is created;echo user is $1 homedir is $2; }


2、使用expect实现自动登录系统。

#!/usr/bin/expect

spawn ssh 192.168.37.7

expect {

"yes/no" { send "yes\n";exp_continue }

"password" { send "123456\n" }

}

interact

3、简述linux操作系统启动流程







4、破解centos7 密码

启动时任意键暂停启动

按e键进入编辑模式

将光标移动linux16开始的行,改为rw init=/sysroot/bin/sh

按ctrl-x启动

chroot /sysroot

passwd root

touch /.autorelabel

exit

reboot

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。