网卡设为ethX形式

if ! grep -q "net.ifnames=0 biosdevname=0" /boot/grub/grub.cfg; then
    echo 'GRUB_TIMEOUT=0' >/etc/default/grub.d/15_timeout.cfg
    echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX net.ifnames=0 biosdevname=0"' >/etc/default/grub.d/15_cmdline.cfg
    grub-mkconfig -o /boot/grub/grub.cfg
fi

设置软件仓库源

此脚本将根据IP地理位置自动修改,若修改失败请手动添加

rgeo=`wget -qO- http://ipip.rehi.org/country_code`
<p>if [ "$rgeo" == "CN" ]; then
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
if [ -f /etc/apt/mirrors/debian.list ]; then
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/mirrors/debian.list
fi
if [ -f /etc/apt/mirrors/debian-security.list ]; then
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/mirrors/debian-security.list
fi
fi</p>
<p>apt update

重置ssh服务证书

若使用第三方镜像请务必执行此操作,防止密钥泄露

ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -P "" -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key

允许root使用密码从ssh登录

cat > /etc/ssh/sshd_config.d/my.conf <<EOF
Port 22
PermitRootLogin yes
PasswordAuthentication yes
PubkeyAcceptedKeyTypes=+ssh-rsa
EOF

扩容硬盘分区

云服务器硬盘可能为/dev/vda

if ! type growpart >/dev/null 2>&1; then
apt install -y cloud-guest-utils
fi</p>
<p>if [ -e /dev/sda1 ]; then
growpart /dev/sda 1
resize2fs /dev/sda1
fi