为什么 ssh 忽略用户配置文件

为什么 ssh 忽略用户配置文件

ssh 不是首先从用户配置文件读取,而是从系统范围的配置中读取。
这是我的 ssh 详细跟踪(使用本地用户,而不是 root 用户):

-bash-4.1$ ssh -v [email protected]
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: Connection established.
debug1: identity file /var/www/html/.ssh/identity type -1
debug1: identity file /var/www/html/.ssh/identity-cert type -1
debug1: identity file /var/www/html/.ssh/id_rsa type -1
debug1: identity file /var/www/html/.ssh/id_rsa-cert type -1
debug1: identity file /var/www/html/.ssh/id_dsa type -1
debug1: identity file /var/www/html/.ssh/id_dsa-cert type -1
debug1: identity file /var/www/html/.ssh/id_ecdsa type -1
debug1: identity file /var/www/html/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /var/www/html/.ssh/identity
debug1: Trying private key: /var/www/html/.ssh/id_rsa
debug1: Trying private key: /var/www/html/.ssh/id_dsa
debug1: Trying private key: /var/www/html/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

因此,它无法找到我的密钥,其位置在本地配置中指定。为什么 ssh 会忽略位于 的本地配置文件~/.ssh/config?该文件有 rwe 规则 600 。我也尝试了 mod 400,但无济于事。

答案1

确保所有者~/.ssh/config 与您登录的用户名相匹配。从上面的截图来看,您似乎已登录,因此您应该从 root shellwww-data执行。chown www-data:www-data /var/www/html/.ssh/config

请注意,如果你有 Apache 指向/var/www/html它是一个极其糟糕的事情将您的 SSH 密钥放在 Apache 可能接触到的任何地方,因为简单的配置错误或 PHP 应用程序漏洞/配置错误都可能将您的密钥泄露给任何可以访问 Apache 的人。您应该将用户的主目录更改为Apache 可以访问的任何目录之外的内容。您可以通过在其他地方手动创建目录(例如或创建)www-data来做到这一点,编辑 的条目,您需要注销并重新登录才能使更改生效。/etc/systemhome/www-data/home/www-datawww-data/etc/passwd

答案2

使用配置文件中的主机标识符,然后它将使用配置中为该主机指定的任何内容(与 DNS 名称不同)。例如:

Host github
HostName github.com
IdentityFile ~/.ssh/id_rsa.pem
User srg-b

答案3

.ssh目录无法被 ssh 进程执行时,就会发生这种情况。无论如何,这种/var/www/html/.ssh情况都不应该存在,所以这里面一定有什么可疑之处。

答案4

跑步

sudo chown -R <user> ~/.ssh

...经过几个小时的努力诊断,终于解决了这个烦人的问题 - 由于某种原因,SSH 文件夹中至少有一个文件不属于该目录所属的用户。

相关内容