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


1

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

-bash-4.1$ ssh -v srg-b@github.com
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,但无济于事。


2
你说配置在~/.ssh/config,但告诉我们完整的路径?是吗/var/www/html/.ssh/config,因为这似乎是SSH正在寻找的路径。什么帐户用于ssh?
Zoredache 2016年

它可能是来自Apache或nginx安装的www-data用户。
LawrenceC

Answers:


4

确保〜/ .ssh / config 的所有者与您登录的用户名相匹配。从您上面的捕获看起来您已登录,www-data因此您应该chmod www-data:www-data /var/www/html/.ssh/config从root shell执行。

请注意,如果你有阿帕奇指出,/var/www/html这是一个极坏的THING有你的SSH密钥的任何地方,那里是一个可能性的Apache能碰到他们,一个简单的错误配置或PHP应用程序开发/错误配置可以揭示你的钥匙给任何人谁可以访问Apache的。您应该将www-data用户的主目录更改为Apache可以访问的任何目录之外的目录。您可以通过手动创建一个目录的其他地方(例如,做这个/etc/systemhome/www-data或做/home/www-data)编辑www-data条目/etc/passwd,你将需要注销并重新使更改生效。


1

.ssh目录不能由ssh进程执行时,会发生这种情况。/var/www/html/.ssh在任何情况下都不可能存在,所以那里有一些可疑的东西。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.