新增rustdesk

This commit is contained in:
2026-04-28 17:07:08 +08:00
parent 97c6b99b58
commit 9a5a3f8475
4 changed files with 108 additions and 5 deletions

View File

@@ -282,6 +282,35 @@ setup_firewall_base() {
fi
}
# ===== 配置 SSH 公钥认证 =====
# 用法: setup_ssh_key <公钥内容>
# 将公钥写入 ~/.ssh/authorized_keys自动设置正确权限
setup_ssh_key() {
local pubkey="$1"
if [ -z "$pubkey" ]; then
warn "SSH_PUBLIC_KEY 为空,跳过 SSH 密钥配置"
return
fi
step "配置 SSH 密钥认证"
mkdir -p /root/.ssh
chmod 700 /root/.ssh
touch /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
# 幂等:相同公钥不重复写入
if grep -qF "$pubkey" /root/.ssh/authorized_keys 2>/dev/null; then
log "SSH 公钥已存在,跳过"
else
echo "$pubkey" >> /root/.ssh/authorized_keys
log "SSH 公钥已添加到 /root/.ssh/authorized_keys"
fi
log "SSH 密钥认证配置完成,后续可使用密钥连接,无需输入密码"
}
# ===== 开放额外端口 =====
# 用法: firewall_allow_port <端口> [描述]
firewall_allow_port() {
@@ -428,6 +457,11 @@ _base_main() {
install_certbot
setup_firewall_base
# 配置 SSH 公钥认证(若 .env 中设置了 SSH_PUBLIC_KEY
if [ -n "${SSH_PUBLIC_KEY:-}" ]; then
setup_ssh_key "$SSH_PUBLIC_KEY"
fi
echo ""
log "===== 基础环境安装完成 ====="
log "已安装: Docker $(docker --version 2>/dev/null | grep -o '[0-9.]*' | head -1)"