经验分享 – 安装 Debian 系统后的几组常用命令

网卡设为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://myip.rpc.im/country_code`

if [ "$rgeo" == "CN" ]; then
    sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
fi

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
EOF

扩容硬盘分区(云服务器硬盘可能为/dev/vda)

if ! type growpart >/dev/null 2>&1; then
    apt install -y cloud-guest-utils
fi

if [ -e /dev/sda1 ]; then
    growpart /dev/sda 1
    resize2fs /dev/sda1
fi

正文完