Ssh Can';t推送到bitbucket,权限被拒绝(公钥)
我正试图将我的项目推到我的bitbucket上,我花了大约4天的时间处理这个问题,花了无数的时间解决问题/页面/疑难解答/教程。我不知所措,非常沮丧。我以前做过,但在不同的计算机上…无论如何,这是我得到的代码/响应Ssh Can';t推送到bitbucket,权限被拒绝(公钥),ssh,bitbucket,ssh-keys,Ssh,Bitbucket,Ssh Keys,我正试图将我的项目推到我的bitbucket上,我花了大约4天的时间处理这个问题,花了无数的时间解决问题/页面/疑难解答/教程。我不知所措,非常沮丧。我以前做过,但在不同的计算机上…无论如何,这是我得到的代码/响应 ~/dev/sample_app git push -u origin --all The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established. RSA key fingerprint
~/dev/sample_app git push -u origin --all
The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established.
RSA key fingerprint is 81:7b:2c:f5:6f:18:2b:7c:4b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
~/dev/sample_app
我在运行10.8.4的mac电脑上
所以取得了一些进展,最初没有.ssh文件夹,所以我在一开始就这样创建了,没有已知的\u hosts文件,所以我运行了
ssh -T git@bitbucket.org
我选择了“是”,这创建了一个已知的_hosts文件,当我再次尝试推送时,我得到:
~/dev/sample_app git push -u origin --all
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
My.ssh文件夹是700,里面的密钥都是600。一个更可持续的解决方案是编辑
.bashrc
(例如vi~/.bashrc
),然后添加以下行(替换密钥名)
ssh添加~/.ssh/您的密钥
这将在启动shell时自动加载密钥您可以在~/.ssh/config文件中设置IdentityFile标志文件,如下所示:
Host bitbucket.org
IdentityFile ~/.ssh/id_rsa
Host bitbucket.org
Hostname bitbucket.org
IdentityFile <location-of-.ssh-directory>/bb-rsa
IdentitiesOnly=yes
当你跑的时候
ssh git@bitbucket.org
ssh客户端允许您选择一个文件,从中读取RSA或DSA身份验证的标识(私钥)
这可能会让系统管理员感到恐惧,但在遇到这个问题(Windows)后,我放弃了SSH,转而使用HTTPS 首次将远程存储库添加到Git时,请替换SSH引用“
git@bitbucket.org...
“带有HTTPS URL”HTTPS://@bitbucket.org
”
您每次都必须输入密码,但特别是在SSH不像*nix系列那样普遍可用的Windows下,与SSH的麻烦相比,我认为这是一个小小的不便。在我的例子中,它解决了从目录添加SSH密钥的问题
~/.ssh/id_rsa.pub
开。我在网站上把它命名为id_rsa.pub
开始时,我添加了另一个为bitbucket创建的密钥,并将其命名为。第一次远程操作成功,但几天后请求被拒绝 在Windows中,@efesaid answer用于解决ssh连接测试的问题。顺便说一句,您可以添加一个-v来查看尝试了哪些键(按名称)以及连接失败的原因 但是,当推到bitbucket时,使用git@bitbucket.org:user/repo.git,主机似乎不是bitbucket.org,因此我仍然遇到权限拒绝问题。我通过(重新)将我的密钥命名为id_rsa(这是ssh测试中尝试的密钥名)解决了这些问题 如果您只有一个rsa密钥,则可以使用此方法。对于多个键,配置文件中的主机可能必须是
bitbucket.org:username
但我不确定这是不是真的,我在Linux(Ubuntu)中也遇到了同样的问题 我使用git中的设置解决了这个问题:
git config --global user.name "Your Name"
git config --global user.email your.email@example.com
使用cat和SSH密钥将公钥打印到bitbucket.org:
$ cat ~/.ssh/id_rsa.pub
添加Bitbucket并向上推存储库:
git remote add origin git@bitbucket.org:<username>/your repository name.git
git push -u origin --all
git远程添加源git@bitbucket.org:/your repository name.git
git push-u原点——全部
就这些 我认为bitbucket指令是最好的。检查ssh是否已安装,如果未安装,请安装它
krasen@krasen-Lenovo-Y50-70:~$ ssh -v
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I xxxxx] [-i identity_file]
[-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port]
[-Q cipher | cipher-auth | mac | kex | key]
[-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] [user@]hostname [command]
krasen@krasen-Lenovo-Y50-70:~$ ls -a ~/.ssh
. .. google_compute_engine google_compute_engine.pub identity identity.pub known_hosts
krasen@krasen-Lenovo-Y50-70:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/krasen/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/krasen/.ssh/id_rsa.
Your public key has been saved in /home/krasen/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx krasen@krasen-Lenovo-Y50-70
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| xx x |
| xxxxx |
| xxxxxxxxx |
| .xxxxxxxx |
| xxxxx |
| xxxxxxxxxxxx|
| xxxxxxxxxxxxx|
| xxxxxxxxxxx |
+-----------------+
krasen@krasen-Lenovo-Y50-70:~$ ls -la ~/.ssh
total 40
drwx------ 2 krasen krasen 4096 Jun 29 14:30 .
drwxr-xr-x 110 krasen krasen 4096 Jun 29 13:00 ..
-rw------- 1 krasen krasen 1675 Mar 18 2015 google_compute_engine
-rw-r--r-- 1 krasen krasen 409 Mar 18 2015 google_compute_engine.pub
-rw------- 1 krasen krasen 1679 Jun 29 13:15 identity
-rw-r--r-- 1 krasen krasen 409 Jun 29 13:15 identity.pub
-rw------- 1 krasen krasen 1679 Jun 29 14:30 id_rsa
-rw-r--r-- 1 krasen krasen 409 Jun 29 14:30 id_rsa.pub
-rw-r--r-- 1 krasen krasen 4698 Jun 29 13:16 known_hosts
krasen@krasen-Lenovo-Y50-70:~$ ssh-agent /bin/bash
检查代理是否已启动
获取此密钥并将其作为密钥添加到bitbucket设置中检查是否存在SSH密钥
ls -al ~/.ssh
复制SSH密钥
cat ~/.ssh/id_rsa.pub | pbcopy
将复制的SSH密钥添加到“Bitbucket设置”、“安全性”、“SSH密钥”中。在我的新鲜Ubuntu 16机器上,我在
~/.SSH
文件夹中缺少文件,所以什么有效:
~/.ssh
ssh-keygen
并命名您的文件,即id\u-rsa
cat~/.ssh/id_rsa.pub | xclip-sel clip
如果您错过了
xclip
只需安装xclip
:)添加密钥
并从剪贴板粘贴密钥神奇-它现在可以工作了:)您可能正在使用ssh作为git源url。尝试像这样删除ssh源代码
git remote rm origin
然后使用HTTPS url添加新的源站,然后再次尝试推送
git remote add origin https://git@bitbucket.org/SOMETHING/SOMETHING.git
git push -u origin master
确保您将来自bitbucket的url粘贴为源地址。我解决了一个类似的问题,我以前使用HTTPS访问存储库,必须通过如下设置url切换到SSH
git remote set-url origin ssh://git@bitbucket.org/...
这可能是显而易见的,但我花了很多时间 运行时检查目的地
git remote-v
在我的例子中,ssh密钥设置得很好,但该命令的输出是:
原点get@github.com:USERNAME/REPOSITORY.git
(注意get而不是git)
而不是
原点git@github.com:USERNAME/REPOSITORY.git
同样,这是一个非常特殊的情况,但是如果您遇到问题,一定要仔细检查这个系统的字符串
可以使用以下命令修复此问题:
git远程设置url源git@github.com:USERNAME/REPOSITORY.git
在使用git config--global user.name“My name”
和
git config--global user.emailmyemail@x.com,我仍然遇到权限被拒绝(公钥)错误的问题。为了解决这个问题,我首先使用
ssh-keygen
并用
pbcopy < ~/.ssh/YOUR_KEY
我遇到的最大问题是,我错过了关键的
ssh add[key]
命令。确保您已切换到终端上的正确用户
在我的例子中,root用户不是在bitbucket设置面板中添加了ssh密钥的用户。使用sudo运行git使其从root用户运行,而我自己的用户就是添加了密钥的用户 我的问题与权限有关 我的项目目录属于
root
,但我是以ubuntu
的身份登录的。如果我输入git命令,例如,git-pull-origin-master
,我将获得被拒绝的权限,因此我使用了s
ssh-add ~/.ssh/YOUR_KEY.
chown -R username_here:username_here project/folder/here
ssh -T git@bitbucket.org
Repositories (R-W-A-D)
Projects (R-W)
Pull request (R-W)
.ssh/config
# Company account
Host company
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_accelya
# Personal account
Host personal
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
# Personal account bitbucket
Host bitbucket
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal_bitbucket
Host bitbucket.org
Hostname bitbucket.org
IdentityFile <location-of-.ssh-directory>/bb-rsa
IdentitiesOnly=yes