069_破解虚拟机密码,无密码登陆虚拟机系统

#!/bin/bash
#该脚本使用 guestmount 工具,Centos7.2 中安装 libguestfs-tools-c 可以获得 guestmount 工具

read -p "请输入虚拟机名称:" name
if virsh domstate $name | grep -q running ;then

# virsh domstate 显示虚拟机当前状态
# grep -q running 查找到running字符串
    echo "破解,需要关闭虚拟机"
    virsh destroy $name
fi

mountpoint="/media/virtimage"
[ ! -d $mountpoint ]  && mkdir $mountpoint
     echo "请稍后..."
if mount | grep -q "$mountpoint" ;then
     umount $mountpoint
fi

guestmount -d $name -i $mountpoint
#将 passwd 中密码占位符号 x 删除,该账户即可实现无密码登陆系统
sed -i "/^root/s/x//" $mountpoint/etc/passwd

猜你喜欢

转载自www.cnblogs.com/luwei0915/p/10518530.html
今日推荐