我用的是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没有密码,但仍然错误。


当前回答

我也犯了同样的错误。

问题是,当将公钥复制到BitBucket(在我的情况下)时,在末尾复制/粘贴了一个不可见的换行符。

因此,在复制公钥时,首先将其复制到记事本,删除末尾的空行,复制并粘贴。

其他回答

请注意(至少对于某些项目),您必须拥有一个带有ssh密钥的github帐户。

查看身份验证代理中列出的密钥(ssh-add -l) (如果你没有看到任何,用ssh-add /path/到/your/key添加一个你现有的密钥(例如:ssh-add ~/.ssh/id_rsa)) (如果你没有任何密钥,首先创建一个。参见:http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html或谷歌ssh-keygen)

要验证您有一个与您的github帐户相关联的密钥:

访问:https://github.com/settings/ssh

您应该至少看到一个键的哈希键与您刚才键入ssh-add -l时看到的某个哈希键相匹配。

如果没有,添加一个,然后再试一次。

我已经使用gh进行了身份验证,创建了新的密钥,等等。问题是我在Ubuntu中安装了带snap的gh,所以生成的新密钥在。/snap/gh/502/。Ssh /,而不是常规的. Ssh路径。

我解决了它复制一切到。ssh文件夹:

cp -a ./snap/gh/502/.ssh/* .ssh/

如果没有,用find找到你的钥匙。- name * .pub

我想,在数字世界里,知道你把钥匙放在哪里仍然是个问题。

我正与同样的问题作斗争,这就是我所做的,我能够克隆回购。我在Mac上遵循了这个步骤。

第一步:检查我们是否已经拥有公共SSH密钥。

打开终端。 输入ls -al ~/。查看是否存在现有的ssh密钥:

检查目录列表,查看是否已经拥有公共SSH密钥。默认public是以下d_dsa之一。酒吧,id_ecdsa。酒吧,id_ed25519。酒吧,id_rsa . pub。

如果你没有找到,那么转到步骤2,否则继续步骤3

步骤2:生成SSH公钥

Open Terminal. Enter the following command with a valid email address that you use for github ssh-keygen -t rsa -b 4096 -C "your_email@example.com" You will see the following in your terminal Generating public/private rsa key pair. When it prompts to"Enter a file in which to save the key," press Enter. This accepts the default file location. When it prompts to Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] Just press enter again. At the prompt, "Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]" press enter if you don't want to Enter same passphrase again: [Type passphrase again] press enter again

这将生成id_rsa.pub

步骤3:添加SSH密钥到SSH -agent

Interminal type eval "$(ssh-agent -s)" Add your SSH key to the ssh-agent. If you are using an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file. Enter this command $ ssh-add -K ~/.ssh/id_rsa Now copy the SSH key and also add it to you github account In terminal enter this command with your ssh file name pbcopy < ~/.ssh/id_rsa.pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

如果用户未生成之前设置的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

当我在工作中得到一台新电脑或换工作时,这些是我遵循的步骤。Mac或Windows

-访问https://github.[yourWorkDomain].com。导航到设置→开发人员设置→个人访问令牌 -生成一个新的令牌 -设置令牌描述,只检查范围的“repo”框(这将给你repo:status, repo_deployment, public_repo, repo:invite access)

-在你得到令牌后,复制它(不要导航离开,确认接下来的两步工作) -尝试再次克隆回购(使用“https”) -用户名使用你的用户名 -对于密码,粘贴您复制的令牌 -所有未来的请求现在应该工作,而不需要您的用户名和密码。