From c5aaf8798cb86e83c812581a7da7912a9f41fd02 Mon Sep 17 00:00:00 2001 From: spiritLHLS <103393591+spiritLHLS@users.noreply.github.com> Date: Sat, 8 Apr 2023 22:34:40 +0800 Subject: [PATCH] Create rebuild_qcow2.sh --- rebuild_qcow2.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 rebuild_qcow2.sh diff --git a/rebuild_qcow2.sh b/rebuild_qcow2.sh new file mode 100644 index 0000000..b77b44d --- /dev/null +++ b/rebuild_qcow2.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +apt-get update +apt-get install libguestfs-tools +sudo apt-get install rng-tools + +qcow_file=/root/qcow/ubuntu22.qcow2 +echo "启用SSH功能..." +virt-customize -a $qcow_file --run-command "systemctl enable ssh" +virt-customize -a $qcow_file --run-command "systemctl start ssh" +echo "启用root登录..." +virt-customize -a $qcow_file --run-command "sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config" +virt-customize -a $qcow_file --run-command "systemctl restart sshd" +echo "创建备份..." +cp $qcow_file ${qcow_file}.bak +echo "复制新文件..." +cp $qcow_file ${qcow_file}.tmp +echo "覆盖原文件..." +mv ${qcow_file}.tmp $qcow_file +rm -rf *.bak +echo "修改完成"