Update ssh-pub.sh

This commit is contained in:
starry
2025-11-29 22:12:32 +08:00
committed by GitHub
parent 1e5feebe54
commit 898d3246d2

View File

@@ -125,40 +125,23 @@ setup_ssh_key() {
}
restart_ssh() {
for svc in sshd ssh; do
# systemd (Rocky, Ubuntu, Debian, CentOS 等)
if command -v systemctl >/dev/null 2>&1; then
if systemctl list-unit-files | grep -q "^${svc}.service"; then
if systemctl restart "$svc" 2>/dev/null; then
echo "SSH 服务已重启 (systemctl)"
if systemctl restart sshd 2>/dev/null || systemctl restart ssh 2>/dev/null; then
echo "SSH 服务已重启 (systemd)"
return 0
fi
fi
fi
done
for cmd in "service ssh restart" "service sshd restart"; do
if $cmd 2>/dev/null; then
echo "SSH 服务已重启 (service)"
return 0
fi
done
for cmd in "/etc/init.d/ssh restart" "/etc/init.d/sshd restart"; do
if $cmd 2>/dev/null; then
echo "SSH 服务已重启 (init.d)"
return 0
fi
done
# OpenRC (Alpine Linux)
if command -v rc-service >/dev/null 2>&1; then
if rc-service sshd restart 2>/dev/null; then
if rc-service sshd restart 2>/dev/null || rc-service ssh restart 2>/dev/null; then
echo "SSH 服务已重启 (OpenRC)"
return 0
fi
fi
echo "警告: 无法自动重启 SSH请手动重启"
echo "警告: 无法自动重启 SSH 服务,请手动重启"
return 1
}