Skip to content

OpenSSH

Coolify 使用 SSH 连接到您的服务器并部署应用程序。即使使用运行 Coolify 的 localhost 服务器,这也是适用的。

警告

用于运行 Coolify 安装脚本的用户的 SSH 密钥不得设置密码短语或启用双因素认证,否则连接将失败。

SSH 设置配置

这些设置需要在运行 Coolify 安装脚本之前手动配置:

  1. 编辑 SSH 配置

    bash
    nano /etc/ssh/sshd_config

    确保存在以下设置:

    ssh
    PermitRootLogin prohibit-password
    PubkeyAuthentication yes

    注意

    PermitRootLogin 选项可以设置为 yeswithout-passwordprohibit-password。为了增强安全性,我们建议使用 prohibit-password

    警告!

    在将 PermitRootLogin 设置为 prohibit-password 之前,确保将您的 SSH 密钥添加到 ~/.ssh/authorized_keys 文件中,否则您可能会被锁定在服务器之外。

  2. 重启 SSH 服务

SystemD:

bash
# Debian/Ubuntu 系列 (systemd)
systemctl restart ssh  # 如有需要,也可以使用 `systemctl restart sshd`

# CentOS/RHEL 7+ (systemd)
systemctl restart sshd

OpenRC:

bash
# Alpine/Gentoo (OpenRC)
rc-service sshd restart

# 旧版 Ubuntu (Upstart)
service sshd restart

# 传统 Linux (SysVinit)
# /etc/init.d/sshd restart

手动配置

注意

以下步骤由 Coolify 安装脚本自动处理。只有在自动设置失败时才需要手动配置。

  1. 安装 OpenSSH 服务器

    Ubuntu/Debian/PopOS

    bash
    apt update && apt install -y openssh-server
    systemctl enable --now sshd

    CentOS/RHEL/Fedora/Rocky

    bash
    dnf install -y openssh-server
    systemctl enable --now sshd

    SLES/openSUSE

    bash
    zypper install -y openssh
    systemctl enable --now sshd

    Arch Linux

    bash
    pacman -Sy --noconfirm openssh
    systemctl enable --now sshd

    Alpine Linux

    bash
    apk add openssh
    rc-update add sshd
    rc-service sshd start
  2. 配置 SSH 设置 按照上面的 SSH 设置配置 部分进行操作。

  3. 生成和配置 SSH 密钥

    bash
    # 生成 SSH 密钥对
    ssh-keygen -t ed25519 -a 100 \
        -f /data/coolify/ssh/keys/id.root@host.docker.internal \
        -q -N "" -C root@coolify
    
    # 设置正确的所有权
    chown 9999 /data/coolify/ssh/keys/id.root@host.docker.internal
    
    # 将公钥添加到 authorized_keys
    mkdir -p ~/.ssh
    cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys
    
    # 设置适当的权限
    chmod 600 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
  4. 在 Coolify UI 中配置

    1. 导航到 密钥和令牌 菜单
    2. 进入 私钥 部分
    3. 添加私钥
    4. 在您的本地主机服务器设置中配置密钥