跳转到内容
搜索 AlmaLinux 文档

    浏览当前文档目录

    AlmaLinux 10 安装后第一步:SSH 密钥登录与 drop-in 配置层

    在 almalinux:10 容器(aarch64;10.2 Lavender Lion,openssh-server 9.9p1-29.el10_2,2026-10-29 实时仓库)中实际执行:安装 openssh-server/clients、sshd -T 默认值读取、/etc/ssh/sshd_config.d/ 三个 drop-in 的内容读取、ssh-keygen 生成 ed25519 密钥对。原始日志:plans/content-expansion/evidence/logs/alma-ssh-key-login.log。

    本页没有执行:实机端到端 ssh 登录、systemctl reload sshd 后的行为验证、SELinux 相关操作。相关段落均标注「未实测」。

    EL10 的 /etc/ssh/sshd_config 开头就是:

    Include /etc/ssh/sshd_config.d/*.conf

    容器里装完 openssh-server 后,这个目录有三个文件,各有分工、来自不同层:

    文件来源层内容要点
    25-permitrootlogin.confAlma 发行层特有PermitRootLogin yes
    40-redhat-crypto-policies.confRHEL 系通用Include /etc/crypto-policies/back-ends/opensshserver.config
    50-redhat.confRHEL 系通用UsePAM yes、GSSAPIAuthentication yes、X11Forwarding yes 等

    对 PermitRootLogin/PasswordAuthentication 这类单值指令,sshd 取第一次出现的值,而 Include 在主配置文件最前面——所以 drop-in 目录里序号小的文件反而优先生效,sshd_config 主体里的同名指令对这类指令作废(HostKey、Match、AcceptEnv 等多值/块指令不适用此规则)。

    容器实测 sshd -T 输出包含 permitrootlogin yes,出处就是上面那个 25-permitrootlogin.conf。

    它和「安装器默认禁 root」不矛盾:

    • Anaconda 图形安装默认把 Root Account 留空禁用(安装摘要屏显示 Root account is disabled);
    • 但只要你安装时设了 root 密码,装出来的系统就允许 root 密码登录——因为 sshd 侧被 Alma 的 drop-in 显式放行了。

    这两个默认值叠加的实际含义:设了 root 密码的 AlmaLinux 10 默认可以被 root 用密码 SSH 登录。如果你的安全基线不允许这一点,装完第一件事就该按下文方式收紧,而不是指望发行版默认。

    Terminal window
    # 最小化安装可能没有客户端工具
    sudo dnf install -y openssh-clients
    # 生成 ed25519 密钥对(推荐; passphrase 建议非空)
    ssh-keygen -t ed25519
    # 部署公钥到目标机
    ssh-copy-id user@host
    # 或手工:把 ~/.ssh/id_ed25519.pub 内容追加到目标机 ~/.ssh/authorized_keys

    权限三件套(sshd 会因权限过宽拒用公钥):

    Terminal window
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    # 属主必须是登录用户本人

    authorizedkeysfile 的默认值就是 .ssh/authorized_keys(sshd -T 实测),不需要额外配置。

    要禁密码登录、禁 root 登录,不要直接编辑 50-redhat.conf——它属于发行版包,升级时可能被覆盖回默认。做法是在 drop-in 目录放一个序号更小的自己的文件:

    Terminal window
    sudo tee /etc/ssh/sshd_config.d/10-hardening.conf <<'EOF'
    PasswordAuthentication no
    PermitRootLogin prohibit-password
    EOF
    # 校验语法,再热加载
    sudo sshd -t
    sudo systemctl reload sshd
    • 端到端 ssh 登录(密钥被接受、密码被拒)的实机行为:未实测
    • systemctl reload sshd 对已有连接与新连接的影响:未实测
    • SELinux 对 ~/.ssh/authorized_keys 上下文的要求(非标准路径场景):未实测,见 SELinux 主题页