Windows 10 上 bitbucket 服务器的多个 ssh 密钥
Multiple ssh-keys for bitbucket server on Windows 10
我有 2 个 bitbucket 帐户。一个 - 用于工作目的,另一个用于我的宠物项目。
我遵循了 bitbucket 文档,how to setup multiple ssh-keys。
用于工作目的的帐户有用户名:user4work
。
home pet-projects 帐户的用户名:user4home
.
~\.ssh\config
文件看起来像这样:
IdentityFile ~/.ssh/user4work
IdentityFile ~/.ssh/user4home
Host bitbucket.org-user4work
HostName bitbucket.org
User git
IdentityFile ~/.ssh/user4work
IdentitiesOnly yes
Host bitbucket.org-user4home
HostName bitbucket.org
User git
IdentityFile ~/.ssh/user4home
IdentitiesOnly yes
文件夹 ~/.ssh/
有以下文件:
config
known_hosts
user4home
user4home.pub
user4work
user4work.pub
*.pub 文件的内容在相应的 bitbucket 帐户设置中设置为 SSH 密钥。
“OpenSSH 身份验证代理”(ssh-agent) 服务设置为在 Windows 启动时自动启动。
问题是,git 命令可以通过 ssh 访问 user4work 帐户,但不能访问 user4home 帐户。
通过 ssh 从 user4home 的存储库中克隆某些内容后,我收到 Forbidden
错误。
当我在 git bash window 中调用 ssh -v bitbucket.org
时,我得到以下输出。
$ ssh -v git@bitbucket.org
OpenSSH_8.0p1, OpenSSL 1.1.1c 28 May 2019
debug1: Reading configuration data /c/Users/Rafael/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to bitbucket.org [18.234.32.157] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Rafael/.ssh/user4work type 0
debug1: identity file /c/Users/Rafael/.ssh/user4work-cert type -1
debug1: identity file /c/Users/Rafael/.ssh/user4home type 0
debug1: identity file /c/Users/Rafael/.ssh/user4home-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0
debug1: Remote protocol version 2.0, remote software version conker_51a1cf6f2c app-141
debug1: no match: conker_51a1cf6f2c app-141
debug1: Authenticating to bitbucket.org:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:abcdef1234567890
debug1: Host 'bitbucket.org' is known and matches the RSA host key.
debug1: Found key in /c/Users/Rafael/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/Rafael/.ssh/user4work RSA SHA256:xxxxxxxxxxxxxxxxxxxxx explicit
debug1: Will attempt key: /c/Users/Rafael/.ssh/user4home RSA SHA256:yyyyyyyyyyyyyyyyyyyyy explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/Rafael/.ssh/user4work RSA SHA256:xxxxxxxxxxxxxxxxxxxxx explicit
debug1: Server accepts key: /c/Users/Rafael/.ssh/user4work RSA SHA256:xxxxxxxxxxxxxxxxxxxxx explicit
debug1: Authentication succeeded (publickey).
Authenticated to bitbucket.org ([18.234.32.157]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
logged in as user4work
You can use git or hg to connect to Bitbucket. Shell access is disabled
debug1: channel 0: free: client-session, nchannels 1
Connection to bitbucket.org closed.
Transferred: sent 3404, received 1988 bytes, in 0.3 seconds
Bytes per second: sent 13427.0, received 7841.6
debug1: Exit status 0
如果在 ~/.ssh/config
文件中,我将前两行替换为
IdentityFile ~/.ssh/user4work
IdentityFile ~/.ssh/user4home
至
IdentityFile ~/.ssh/user4home
IdentityFile ~/.ssh/user4work
然后 user4home 帐户在 git 中通过 ssh 工作,但 user4work 不工作。
我想我在这里遗漏了一些东西。有什么想法吗?
谢谢。
当您想使用工作凭据访问存储库时,您应该将克隆 URL 的 git@bitbucket.org
部分替换为 bitbucket.org-user4work
当您想使用个人凭据访问存储库时,您应该将克隆 URL 的 git@bitbucket.org
部分替换为 bitbucket.org-user4home
因此,例如,如果您有一个最初使用以下方法克隆的工作存储库:
git clone git@bitbucket.org:organization/project.git
你应该 运行
git clone bitbucket.org-user4work:organization/project.git
我有 2 个 bitbucket 帐户。一个 - 用于工作目的,另一个用于我的宠物项目。
我遵循了 bitbucket 文档,how to setup multiple ssh-keys。
用于工作目的的帐户有用户名:user4work
。
home pet-projects 帐户的用户名:user4home
.
~\.ssh\config
文件看起来像这样:
IdentityFile ~/.ssh/user4work
IdentityFile ~/.ssh/user4home
Host bitbucket.org-user4work
HostName bitbucket.org
User git
IdentityFile ~/.ssh/user4work
IdentitiesOnly yes
Host bitbucket.org-user4home
HostName bitbucket.org
User git
IdentityFile ~/.ssh/user4home
IdentitiesOnly yes
文件夹 ~/.ssh/
有以下文件:
config
known_hosts
user4home
user4home.pub
user4work
user4work.pub
*.pub 文件的内容在相应的 bitbucket 帐户设置中设置为 SSH 密钥。
“OpenSSH 身份验证代理”(ssh-agent) 服务设置为在 Windows 启动时自动启动。
问题是,git 命令可以通过 ssh 访问 user4work 帐户,但不能访问 user4home 帐户。
通过 ssh 从 user4home 的存储库中克隆某些内容后,我收到 Forbidden
错误。
当我在 git bash window 中调用 ssh -v bitbucket.org
时,我得到以下输出。
$ ssh -v git@bitbucket.org
OpenSSH_8.0p1, OpenSSL 1.1.1c 28 May 2019
debug1: Reading configuration data /c/Users/Rafael/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to bitbucket.org [18.234.32.157] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Rafael/.ssh/user4work type 0
debug1: identity file /c/Users/Rafael/.ssh/user4work-cert type -1
debug1: identity file /c/Users/Rafael/.ssh/user4home type 0
debug1: identity file /c/Users/Rafael/.ssh/user4home-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0
debug1: Remote protocol version 2.0, remote software version conker_51a1cf6f2c app-141
debug1: no match: conker_51a1cf6f2c app-141
debug1: Authenticating to bitbucket.org:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:abcdef1234567890
debug1: Host 'bitbucket.org' is known and matches the RSA host key.
debug1: Found key in /c/Users/Rafael/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/Rafael/.ssh/user4work RSA SHA256:xxxxxxxxxxxxxxxxxxxxx explicit
debug1: Will attempt key: /c/Users/Rafael/.ssh/user4home RSA SHA256:yyyyyyyyyyyyyyyyyyyyy explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/Rafael/.ssh/user4work RSA SHA256:xxxxxxxxxxxxxxxxxxxxx explicit
debug1: Server accepts key: /c/Users/Rafael/.ssh/user4work RSA SHA256:xxxxxxxxxxxxxxxxxxxxx explicit
debug1: Authentication succeeded (publickey).
Authenticated to bitbucket.org ([18.234.32.157]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
logged in as user4work
You can use git or hg to connect to Bitbucket. Shell access is disabled
debug1: channel 0: free: client-session, nchannels 1
Connection to bitbucket.org closed.
Transferred: sent 3404, received 1988 bytes, in 0.3 seconds
Bytes per second: sent 13427.0, received 7841.6
debug1: Exit status 0
如果在 ~/.ssh/config
文件中,我将前两行替换为
IdentityFile ~/.ssh/user4work
IdentityFile ~/.ssh/user4home
至
IdentityFile ~/.ssh/user4home
IdentityFile ~/.ssh/user4work
然后 user4home 帐户在 git 中通过 ssh 工作,但 user4work 不工作。
我想我在这里遗漏了一些东西。有什么想法吗?
谢谢。
当您想使用工作凭据访问存储库时,您应该将克隆 URL 的 git@bitbucket.org
部分替换为 bitbucket.org-user4work
当您想使用个人凭据访问存储库时,您应该将克隆 URL 的 git@bitbucket.org
部分替换为 bitbucket.org-user4home
因此,例如,如果您有一个最初使用以下方法克隆的工作存储库:
git clone git@bitbucket.org:organization/project.git
你应该 运行
git clone bitbucket.org-user4work:organization/project.git