我用的是Mac雪豹,刚刚安装了git。
我只是试了
git clone git@thechaw.com:cakebook.git
但这给了我这个错误:
Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
我错过了什么?
我也试过做ssh-keygen没有密码,但仍然错误。
如果你的问题最近突然出现(2021年下半年),这可能是由不兼容的哈希算法引起的。
截至本文(2021年10月),Git for windows的最新版本是2.33.1(发布说明),它已经采用了最新的OpenSSH 8.8p1(发布说明),而OpenSSH 8.8p1反过来已经弃用了SHA-1。同时,如果远程Git存储库仍然坚持SHA-1,则身份验证将失败。
要看看你是否会陷入这种情况,检查你的软件版本:
ssh -V
git --version
然后,您应该检查OpenSSH 8.8/8.8p发行说明中的“潜在不兼容更改”部分。
博士TL;
解决方案1:通过将此添加到~/中,再次启用SHA-1。ssh /配置文件:
Host <remote>
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
请记住将<remote>替换为远程存储库的主机名。
解决方案2:使用ECDSA或Ed25519而不是RSA重新生成密钥对。例如:
ssh-keygen -t ecdsa -C <comment>
记住用你自己的助记短语替换<comment>。然后,将生成的公钥上传到远程存储库。
供你参考,我在访问Gitee.com时遇到了这个提示信息,Gitee.com在他们的服务器上使用golang.org/x/crypto/ssh,并在这里发布了一个关于这个问题的页面(中文)。
git@gitee.com: Permission denied (publickey).
如果用户未生成之前设置的ssh公私钥对
此信息在聊天上工作,但可以应用于所有其他支持SSH pubkey身份验证的git存储库。(参见[gitolite][1], gitlab或github。)
首先设置您自己的公钥/私钥对集。这
可以使用DSA或RSA,所以基本上你设置的任何密钥都可以工作。
在大多数系统上,您可以使用ssh-keygen。
First you'll want to cd into your .ssh directory. Open up the terminal and run:
cd ~/.ssh && ssh-keygen
Next you need to copy this to your clipboard.
On OS X run: cat id_rsa.pub | pbcopy
On Linux run: cat id_rsa.pub | xclip
On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to @orion elenzil)
Add your key to your account via the website.
Finally setup your .gitconfig.
git config --global user.name "bob"
git config --global user.email bob@...
(don't forget to restart your command line to make sure the config is reloaded)
That's it you should be good to clone and checkout.
更多信息请访问https://help.github.com/articles/generating-ssh-keys(感谢@Lee Whitney)
[1]: https://github.com/sitaramc/gitolite
-
如果用户已经生成了之前设置的ssh公私钥对
检查哪个密钥已被授权在您的github或gitlab帐户设置
确定必须从本地计算机关联哪个相应的私钥
Eval $(ssh agent -s)
定义键的位置
ssh-add ~ / . ssh / id_rsa