feat: 增加第一次启动触发的用户脚本"如果有安装ssh server, 允许root用户远程密码登录"
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user