安装 Debian 系统后的几组常用命令
网卡设为ethX
形式
将不规则的网卡名改为ethX
形式,如eth0
、eth1
等
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地理位置自动修改,若修改失败请手动添加
if [ "$(wget -qO- http://ipip.rehi.org/country_code)" == "CN" ]; then
if [ -f /etc/apt/sources.list ]; then
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
fi
if [ -d /etc/apt/mirrors ]; then
for lf in `ls /etc/apt/mirrors/*.list`; do
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' $lf
done
fi
apt update
fi
重置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
使用密码远程登录
允许root
使用密码或rsa
密钥登录
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
if [ -e /dev/sda1 ]; then
growpart /dev/sda 1
resize2fs /dev/sda1
fi