我从两个不同的帐户使用 github,一个是专业的,一个是个人的。当 git 将一些代码推送到我的个人帐户上的存储库时,它试图使用专业帐户的用户名推送
git push origin master说:
Permission to X/abc.git denied to Y
fatal: unable to access 'https://github.com/X/abc.git/': The requested URL returned error: 403
然而 git remote -v 说:
origin https://github.com/X/abc.git (fetch)
origin https://github.com/X/abc.git (push)
我已经检查了
1- 我的 ssh 密钥存在于我的个人帐户
2- O/p of ssh@github.com -v:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: identity file /Users/akash.bansal/.ssh/id_rsa type 1
debug1: identity file /Users/akash.bansal/.ssh/id_rsa-cert type -1
debug1: identity file /Users/akash.bansal/.ssh/id_dsa type -1
debug1: identity file /Users/akash.bansal/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
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
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/akash.bansal/.ssh/known_hosts:77
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/akash.bansal/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_CTYPE = UTF-8
PTY allocation request failed on channel 0
Hi X! You've successfully authenticated, but GitHub does not provide shell access.
Run Code Online (Sandbox Code Playgroud)
3- git config user.name
X
4- git config user.email
X's email
5- git config 读取
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/X/abc.git
fetch = +refs/heads/*:refs/remotes/origin/*
Run Code Online (Sandbox Code Playgroud)
PS 这个 repo 目录是在本地创建的,然后尝试与远程目录链接。如果我克隆一个远程目录,一切正常。请告诉我我缺少什么?
配置user.name和user.email仅在提交时相关。这就是 Git 将作为提交的作者和提交者写入提交对象的内容。但是,它不会影响对远程存储库的任何身份验证;Git其实没有认证的概念,只有连接的传输层提供。
在您的情况下,您使用的是 SSH。SSH 将使用公钥/私钥组合来验证您的身份。默认情况下,SSH 将使用位于 的密钥~/.ssh/id_rsa,这也是您的日志所确认的:
debug1: Offering RSA public key: /Users/akash.bansal/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
Run Code Online (Sandbox Code Playgroud)
因此,该密钥用于对您进行身份验证。它可能属于您的专业帐户,因此 GitHub 只会看到您的专业帐户,而不会授予您访问个人存储库的权限。
为了改变它,您必须提供不同的 SSH 密钥。这做起来有点复杂,因为两个密钥都针对同一个主机 (GitHub)。不过,您可以为此设置 SSH 配置。为此,请创建~/.ssh/config以下内容并将其放入(修改它以匹配您的公钥路径):
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/personal-profile_id_rsa
Run Code Online (Sandbox Code Playgroud)
完成后,您可以使用远程 URL使用您的个人密钥git@github-personal:X/abc.git访问存储库,并使用您的专业密钥访问它。X/abc.gitgit@github.com:X/abc.git
或者,您也可以切换到 HTTPS URL,因为它们允许您在 URL 中指定您的用户名:
https://professional@github.com/X/abc.git
https://personal@github.com/X/abc.git
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
178 次 |
| 最近记录: |