git@github.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
git初始化创建目录
cd /home/git //git仓库
mkdir wx.qiaomaimai
cd wx.qiaomaimai
git init --bare
--Initialized empty Git repository in /home/git/wx.qiaomaimai/---表示创建成功
修改用户组权限
chown -R git:git wx.qiaomaimai
后面就是git clone就可以了
---------------------------------------------------------------------------------------------------------------------
楼主下载git闲置了一段时间,某天心血来潮突然想也写一个项目,就打算用git来管理代码。
当楼主在github上建好仓库以后,就准备开始clone,当楼主去找/Users/***/.ssh/id_rsa.pub发现没有(cd ~/.ssh这里可以先简单的检测下,没有就重新生成),
然后就百度了一下,用ssh-keygen -t rsa -C “你的邮箱”这个命令直接生成,之后在/Users/***/.ssh/目录下就生成了两个文件,
到这里的时候,楼主以为就可以搞定了,然后就开始去clone,
直接复制/Users/***/.ssh/id_rsa.pub的内容,然后在github的SSH and GPG keys新建了一个,填上title粘贴上内容,然后回到终端git clone “你的地址”
结果就报了这个
Cloning into 'xxxx'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
然后楼主各种百度,发现解决这个问题的办法,就是复制/Users/***/.ssh/id_rsa.pub的内容到github上新建的keys上啊,为什么就不行呢?
。。。
。。。。
。。。。。
各种百度,各种查,真的是一万个草泥马啊。。。。。
于是楼主就决定开始重头再来,把刚才生成的/Users/***/.ssh/*,全部删除掉,
第一步,先验证一下用户名邮箱,git config --global --list,楼主之前就放了一个错误,没有验证就直接复制内容去粘贴了,一般第一次安装都是没有的。
第二步,git config --global user.name "yourname",git config --global user.email myemail@qq.com 设置全局用户名和邮箱,
第三步,ssh-keygen -t rsa -C "这里换上你的邮箱",生成秘钥,
接着以为这次总算可以OK了,然后又复制了一遍之前的操作,接着去clone,
!
!
!
!
啃爹啊,结果还是报
Cloning into 'xxxx'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
心碎有没有,楼主感觉自己都快奔溃了,到底是为什么呢?
心里一直反复的说要镇定要镇定,然后又是各种百度,最后终于在一位老哥的博客上找到答案了尼玛的太啃爹了
这里提供一下地址https://blog.csdn.net/chaoyueziji123/article/details/54669555
首先测试一下
ssh git@github.com
Warning: Permanently added the RSA host key for IP address '13.250.000.000' to the list of known hosts.
PTY allocation request failed on channel 0
Hi ******! You've successfully authenticated, but GitHub does not provide shell access.
结果是这样的,大概意思就是这个IP地址RSA主机密钥永久的添加到了你的主机列表中,您已经成功地进行了身份验证,但GITHUB不提供shell访问。
解决办法:
1.ssh -v git@github.com
测试ssh连接是否成功,我的现实如下,跟老哥的不太一样,可以连起来看
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/faye/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com: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:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/faye/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:7ym7jzOz5gT7p8h1Xw4f8a7Jq/0a4yjcyWMRO1BVyL0 /Users/faye/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([13.229.188.59]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-8
debug1: Sending env LC_CTYPE = zh_CN.UTF-8
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi ! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Connection to github.com closed.
Transferred: sent 3020, received 1788 bytes, in 0.8 seconds
Bytes per second: sent 3684.0, received 2181.1
debug1: Exit status 1
然后下面两步就关键了,
先使用 ssh-agent -s
SSH_AUTH_SOCK=/var/folders/c6/_lb54v1d4v14_0j4_nt_1vj00000gp/T//ssh-B57Gx7MencHN/agent.32676; export SSH_AUTH_SOCK;
SSH_AGENT_PID=32677; export SSH_AGENT_PID;
echo Agent pid 32677;
再使用 ssh-add ~/.ssh/id_rsa
Identity added: /Users/faye/.ssh/id_rsa (/Users/faye/.ssh/id_rsa)
最后测试 ssh -T git@github.com
Hi nitt! You've successfully authenticated, but GitHub does not provide shell access.
当显示这一句的时候,就万事大吉了,接着就可以愉快的去clone了,
Cloning into '*****'...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
到这里楼主想说,git这个东西还是很值得去研究的,但是楼主比较懒散,一般只会搞明白怎么去使用就好了
所以以楼主的经验就是一步一步搞
第一步,git config --global --list 验证邮箱
第二步,git config --global user.name "yourname",git config --global user.email myemail@qq.com 设置全局用户名和邮箱,
第三步,ssh-keygen -t rsa -C "这里换上你的邮箱",生成秘钥,
第四步,到git仓库,添加秘钥,
第五部,ssh -T git@github.com 测试一下通不通,不通就是ssh-agent -s ssh-add ~/.ssh/id_rsa 操作这两步
最后clone,药到病除!!!!