feat: 增加第一次启动触发的用户脚本"如果有安装ssh server, 允许root用户远程密码登录"

This commit is contained in:
Olia Lisa
2026-06-24 22:31:31 +08:00
parent b8a9dba5c0
commit 084caf164c
2 changed files with 34 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
#!/bin/sh
# 仅在首次启动时执行(/etc/uci-defaults机制)
SSHD_CONF="/etc/ssh/sshd_config"
# 如果 sshd 配置文件存在,则修改配置
if [ -f "$SSHD_CONF" ]; then
# 允许 root 远程登录
if grep -q "^#*PermitRootLogin" "$SSHD_CONF"; then
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin yes/' "$SSHD_CONF"
else
echo "PermitRootLogin yes" >> "$SSHD_CONF"
fi
# 允许密码登录
if grep -q "^#*PasswordAuthentication" "$SSHD_CONF"; then
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' "$SSHD_CONF"
else
echo "PasswordAuthentication yes" >> "$SSHD_CONF"
fi
fi
# 重启 OpenSSH 服务(如果已安装)
if [ -x /etc/init.d/sshd ]; then
/etc/init.d/sshd enable
/etc/init.d/sshd restart
fi
exit 0