git - 无法使用 git 配置文件进行 ssh

标签 git ssh ssh-keys

我知道它被问了很多次,但我无法得到我的问题的答案。 我正在尝试使用配置文件 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: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83e0f6f1f5e6b1b6b6b2baaef0ebe2b1b6b5c3efeae1f0f0ebadecf1e4" rel="noreferrer noopener nofollow">[email protected]</a>
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
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8adabbdaa98e9e8f6eae9e0f6efe8f6ebeced" rel="noreferrer noopener nofollow">[email protected]</a>'s password:

尝试授予文件访问权限,但均无效。

但奇怪的是当我这样做时ssh user@<ip_address> 它工作得很好。 有人能告诉我哪里出了问题以及出了什么问题

最佳答案

您需要使用:

IdentityFile C:/Users/bean/.ssh/id_rsa

不是问题中的“id_rsa.pub”:您的配置文件必须提及私有(private) key ,而不是公共(public) key 。

关于git - 无法使用 git 配置文件进行 ssh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57913307/

相关文章:

ssh - 无法推送到 bitbucket,权限被拒绝(公钥)

git 树包含重复的文件条目

git - Maven Release Plugin 在 Jenkins Pipeline 中的使用

git - 尝试从 docker 容器内安装使用(私有(private))git 存储库的软件包失败

postgresql - 无法在 Ubuntu 上建立 Postgres pgAdmin SSH 隧道

git - 使用 Docker 容器非 root 用户克隆 GitHub 私有(private)存储库?

sshfs EBCDIC 转 ASCII

git - 我没有 ~/.ssh/config 文件,但多个 GitHub 帐户有效,如何?

git - 可以试运行 `git revert` 吗?

git - 为什么 git 使用 GPG key 签名而不是使用 SSH key ?