【发布时间】:2021-03-05 02:16:34
【问题描述】:
我已经翻遍了,找不到解决办法。它曾经工作过……不久前。
我正在尝试使用 git 将远程存储库克隆到我的本地 Windows 10 工作站。我已经在 VSC、git bash 中尝试过,但没有运气。我已经多次重新生成 ssh 密钥,并确保它们在我的 bitbucket 帐户中。我还让管理员验证我在 bitbucket 中具有权限。我可以使用 https 进行克隆,但由于 terraform init 的模块依赖关系,我也需要 ssh,因为它使用 ssh。
这是我遇到的错误
Cloning into 'terraform'...
git@something.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
关于如何使 ssh 连接正常工作的任何想法?我还验证了 openssh ssh-agent 服务正在运行。
更新输出...我还是不明白
强制使用私钥
PS C:\Users\me> ssh -i c:\users\me\.ssh\id_rsa -Tv git@something.com -p 7999
OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
debug1: Connecting to something.com [1.1.1.1] port 7999.
debug1: Connection established.
debug1: identity file c:\\users\\me\\.ssh\\id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file c:\\users\\me\\.ssh\\id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.6
debug1: Remote protocol version 2.0, remote software version APACHE-SSHD-2.4.0
debug1: no match: APACHE-SSHD-2.4.0
debug1: Authenticating to something.com:7999 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:tbUbYIJrt+P7aWKYsn09IsD+iouWjGiR6am8BaXXXXX
debug1: Host '[something.com]:7999' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\me/.ssh/known_hosts:1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:bvs3ECFl7m4r8SN404IIeuiFG6AoNqfdMCFp+AYXXXX c:\\users\\me\\.ssh\\id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: read_passphrase: can't open /dev/tty: No such file or directory
Enter passphrase for key 'c:\users\me\.ssh\id_rsa':
debug1: Authentication succeeded (publickey).
Authenticated to something.com ([1.1.1.1]:7999).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
shell request failed on channel 0
强制公钥
PS C:\Users\aedle> ssh -i c:\users\me\.ssh\id_rsa.pub -Tv git@ssomething.com -p 7999
OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
debug1: Connecting to something.com [1.1.1.1] port 7999.
debug1: Connection established.
debug1: identity file c:\\users\\me\\.ssh\\id_rsa.pub type 0
debug1: key_load_public: No such file or directory
debug1: identity file c:\\users\\me\\.ssh\\id_rsa.pub-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.6
debug1: Remote protocol version 2.0, remote software version APACHE-SSHD-2.4.0
debug1: no match: APACHE-SSHD-2.4.0
debug1: Authenticating to something.com:7999 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:tbUbYIJrt+P7aWKYsn09IsD+iouWjGiR6am8Ba9XXXX
debug1: Host '[something.com]:7999' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\me/.ssh/known_hosts:1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:bvs3ECFl7m4r8SN404IIeuiFG6AoNqfdMCFp+AXXXXX c:\\users\\me\\.ssh\\id_rsa.pub
debug1: Server accepts key: pkalg ssh-rsa blen 535
Load key "c:\\users\\me\\.ssh\\id_rsa.pub": invalid format
debug1: No more authentication methods to try.
git@something.com: Permission denied (publickey).
我仍然完全迷失了,因为当我回去尝试克隆时,我得到了这个:
git clone ssh://something.com:7999/ter/terraform.git
Cloning into 'terraform'...
git@something.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
总体问题是 git 的 ssh_config 无法在 ~/.ssh/id_rsa 看到我的私钥......所以我必须准确指定 C 上的位置:它是......而不是我的 git config更改此内容并取消注释该行后看起来像这样
Host *
# ForwardAgent no
# ForwardX11 no
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# BatchMode no
# CheckHostIP yes
# AddressFamily any
# ConnectTimeout 0
# StrictHostKeyChecking ask
IdentityFile c:\users\me\.ssh\id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 7999
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,umac-64@openssh.com
# EscapeChar ~
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p gateway.example.com
# RekeyLimit 1G 1h
# UserKnownHostsFile ~/.ssh/known_hosts.d/%k
# Added by git-extra
【问题讨论】:
-
something.com好像是bitbucket.com? ;-) 使用ssh -Tv git@something.com开始调试 -
这是一个内部比特桶。不是云。由此得名 ;)。但这不起作用。被拒绝。我让其他人在同一个 repo 上确认他们可以通过 ssh 克隆就好了。这让我相信这是我机器的本地问题。我只是不知道它可能是什么
-
我要补充一点,我也用我在 cloud bitbucket 中的 repo 进行了尝试,并获得了相同的结果,以排除本地 bitbucket 出现问题的可能性。 ssh-agent 服务正在我的机器上运行。有没有办法强制和保证任何 git 命令使用特定的 ssh 密钥?
-
多种方式。您可以声明
GIT_SSH_COMMAND或git config core.sshCommand。您可以小心craft~/.ssh/config并将这些发明的主机用作您的远程名称。 -
ssh -Tv方法可以帮助您找出被拒绝的原因。添加更多vs 以获得更多调试输出。将可以以这种方式获得的人的输出(让他们运行ssh -Tv git@something.com)与您获得的输出进行比较。有很多调试输出,并不是所有显示为不同的东西都是失败的原因,而是 something 显示为不同的原因。