1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu用户,并自动设置家目录为/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实现自动登录系统。
#!/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、简述linux操作系统启动流程
centos6系统启动流程
1)物理主机加电,主板通电后,CPU开始工作,它执行国定地址处的一段很小的硬编码程序:BIOS,于是BIOS获取CPU的控制权。
2)读取第一个启动设备MBR的引导加载程序(grub)的启动信息
3)加载核心操作系统的核心信息,核心开始解压缩,并尝试驱动所有的硬件设备
4)核心执行init程序,并获取默认的运行信息
5)init程序执行/etc/rc.d/rc.sysinit文件
6)启动核心的外挂模块
7)init执行运行的各个批处理文件(scripts)
8)init执行/etc/rc.d/rc.local
9)执行/bin/login程序,等待用户登录
10)登录之后开始以Shell控制主机
4、破解centos7 密码。
1)启动系统,在grub提供菜单的界面下,在对应菜单项下按键盘的e键,进入编辑模式。
2)通过箭头方向键移动光标到linux16这一行,在这行的末尾处加上rd.break,然后按ctrl+x引导系统。
3)当前根被挂载到/sysroot目录下,并且是只读挂载,需要重新挂载为读写模式,然后使用chroot切到系统原来的根目录下修改密码。
4)执行两次exit退出重启系统,使用新密码登录系统验证。