无法使用 git 配置文件 ssh
Posted
技术标签:
【中文标题】无法使用 git 配置文件 ssh【英文标题】:Unable to ssh using git config file 【发布时间】:2020-01-14 17:17:54 【问题描述】:我知道它被问了很多次,但我无法得到我的问题的答案。 我正在尝试使用配置文件 ssh 到系统。 配置文件是
Host qa
HostName 10.218.70.345
User user
IdentityFile C:/Users/bean/.ssh/id_rsa.pub
Port 22
当我运行以下命令时
$ ssh -v qa
OpenSSH_8.0p1, OpenSSL 1.1.1c 28 May 2019
debug1: Reading configuration data /c/Users/bean/.ssh/config
debug1: /c/Users/bean/.ssh/config line 1: Applying options for qa1
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 10.218.70.345 [10.218.70.345] port 22.
debug1: Connection established.
debug1: identity file C:/Users/bean/.ssh/id_rsa.pub type 0
debug1: identity file C:/Users/bean/.ssh/id_rsa.pub-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000002
debug1: Authenticating to 10.218.70.345:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:CWRMF3n1hQRu6ahabqm/0Ge1KOip6oe/xfJkOUDfRbQ
debug1: Host '10.218.70.345' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/bean/.ssh/known_hosts:10
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: C:/Users/bean/.ssh/id_rsa.pub RSA SHA256:Eb8q2RnFhk+geYicdXwjx/8OqHFsf7qJf7QaTbaGs94 explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: C:/Users/bean/.ssh/id_rsa.pub RSA SHA256:Eb8q2RnFhk+geYicdXwjx/8OqHFsf7qJf7QaTbaGs94 explicit
debug1: Server accepts key: C:/Users/bean/.ssh/id_rsa.pub RSA SHA256:Eb8q2RnFhk+geYicdXwjx/8OqHFsf7qJf7QaTbaGs94 explicit
Load key "C:/Users/bean/.ssh/id_rsa.pub": invalid format
debug1: Next authentication method: password
user@10.218.70.345's password:
尝试授予对文件的访问权限,但均无效。
但奇怪的是当我做ssh user@<ip_address>
它完美地工作。
有人可以告诉哪里出了什么问题
【问题讨论】:
IdentityFile C:/Users/prateek.naik/.ssh/id_rsa.pub
***.com/a/29948797/13317
SSH Key: “Permissions 0644 for 'id_rsa.pub' are too open.” on mac的可能重复
在浏览完所有这些链接之后,只有我发布了这个问题。一个链接建议提供chmod
,另一个链接建议在config
文件中有IdentityFile
行。如果您查看我的文件,它已经有该行并且还提供了所需的权限。如果我只是做ssh user@<ip_address>
我可以登录到盒子
【参考方案1】:
你需要使用:
IdentityFile C:/Users/bean/.ssh/id_rsa
不是问题中的“id_rsa.pub
”:您的配置文件必须提及 private 密钥,而不是公共密钥。
【讨论】:
@Ben.Bean 好的。我已经用你的错误的实际原因重写了答案。 问题中的日志告诉你这个Load key "C:/Users/bean/.ssh/id_rsa.pub": invalid format
。您正在使用您的公钥,而正如 VonC 所说,您应该使用您的私钥。【参考方案2】:
在您的配置文件中添加PreferredAuthentications publickey
。并且不需要使用.pub
作为文件格式
例如:
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
【讨论】:
你能告诉我在哪里以及我需要删除/替换行IdentityFile C:/Users/bean/.ssh/id_rsa.pub
请go through the following link。希望你会发现一些有用的东西。以上是关于无法使用 git 配置文件 ssh的主要内容,如果未能解决你的问题,请参考以下文章