【问题标题】:Openssh Connection does not work with AuthorizedKeysCommandOpenssh 连接不适用于 AuthorizedKeysCommand
【发布时间】:2015-02-22 08:43:40
【问题描述】:

我在 sshd_config 中添加了这些行

AuthorizedKeysCommand /authorizedkeys/authorized-keys
AuthorizedKeysCommandUser ssh-keys

-rwxr-x--- 1 root ssh-keys 712 Dec 23 22:36 /authorizedkeys/authorized-keys 
-rwxr-x---  1 root ssh-keys  712 Dec 23 22:36 authorized-keys

ssh-keys 用户可以执行文件(/authorizedkeys/authorized-keys)。 但我不能 ssh 到服务器; ssh git@myserver.com

在 auth.log 中我可以看到这一行,

error: Unsafe AuthorizedKeysCommand: bad ownership or modes for directory /

如果我向 /authorizedkeys/authorized-keys 文件授予 770 权限,我会收到以下错误,

error: Unsafe AuthorizedKeysCommand: bad ownership or modes for file /authorizedkeys/authorized-keys

我尝试使用 root 作为 AuthorizedKeysCommandUser 并更改了 /authorizedkeys/authorized-keys 文件的权限和所有者。它也没有工作。

我在 ubuntu 14.04 上使用 OpenSSH_6.6.1p1。

注意:我可以使用 authorized_keys 文件进行 ssh 操作

【问题讨论】:

    标签: ssh ssh-keys openssh


    【解决方案1】:
    Unsafe AuthorizedKeysCommand: bad ownership or modes for directory /
    

    它抱怨根目录的所有权或权限。根据源代码,文件、包含文件的目录以及所有父目录(包括根目录)都必须由 root 拥有。所有这些文件和目录的权限都必须是 0755(拒绝对组和其他的写访问)。

    我的猜测是你在你的根目录上设置了组写入权限,或者类似的东西。

    将 0770 权限授予“/authorizedkeys/authorized-keys”也会导致该文件无法通过权限检查。

    为了完整起见,这是发出目录错误的代码部分:

    if (stat(buf, &st) < 0 ||
        (!platform_sys_dir_uid(st.st_uid) && st.st_uid != uid) ||
        (st.st_mode & 022) != 0) {
            snprintf(err, errlen,
                "bad ownership or modes for directory %s", buf);
            return -1;
    }
    

    如果出现以下情况,它会发出该错误:

    1. 对目录的 stat() 调用失败
    2. 文件不属于根目录(“uid”在这里为 0)
    3. 文件的权限包括按组写入或按其他写入。

    【讨论】:

    • 问题出在我的根文件夹 (/) 权限上。谢谢。
    【解决方案2】:

    authorized_keys 文件应为chmod 600.ssh 目录应为chmod 700

    【讨论】:

      【解决方案3】:

      您需要对远程主机上的密钥授予适当的权限:

      [remote-host]$ chmod 755 ~/.ssh
      

      [remote-host]$ chmod 644 ~/.ssh/authorized_keys

      【讨论】:

      • 我想使用 AuthorizedKeysCommand 获取密钥,而不是使用 authorized_keys 文件
      • AuthorizedKeysCommand 在 ~/.ssh/authorized_keys 文件之前读取。 man sshd_config 将提供更多详细信息。
      猜你喜欢
      • 2014-07-11
      • 2012-06-05
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 2013-12-02
      • 1970-01-01
      • 2018-11-24
      相关资源
      最近更新 更多