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


当前回答

同样的错误报告。

修正了使用HTTPS而不是SSH协议的问题。因为我不想为测试PC设置“SSH密钥”。

克隆时将URL更改为HTTPS:

git clone https://github.com/USERNAME/REPOSITORY.git

我的问题有点不同:当添加一个现有的本地回购到远程时,我有URL设置为SSH,通过使用:

git remote add origin ssh://github.com/USERNAME/REPOSITORY.git

要解决这个问题,请将URL重置为HTTPS:

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

顺便说一句,你可以使用命令检查你的URL:

git remote -v
origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

希望这能帮助到像我这样的人。: D

其他回答

Mac操作步骤:

切换用户(sudo su - jenkins) 生成密钥(ssh-keygen -t rsa -b 4096 -C "username")。用户名 是你和詹金斯一起用的。 复制生成的公钥(cat ~/.ssh/id_rsa.pub)。 将密钥粘贴到git帐户。(设置-> SSH和CPG密钥->新建 ssh keys ->输入密钥名称(可以是任意),并将密钥粘贴到 描述)。

伙计们我是这么干的

Open terminal and go to user [See attached image] Open .ssh folder and make sure it doesn't have any file like id_rsa or id_rsa.pub otherwise sometimes it wont properly rewrite files git --version [Check for git installation and version] git config --global user.email "your email id" git config --global user.name "your name" git config --list [make sure you have set your name & email] cd ~/.ssh ssh-keygen, it prompts for saving file, allow it cat ~/.ssh/id_rsa.pub [Access your public key & copy the key to gerrit settings]

注意:你不应该在Git中使用sudo命令。如果您有非常好的理由必须使用sudo,那么请确保您在每个命令中都使用它(此时使用su作为根来获取shell可能更好)。如果您不使用sudo生成SSH密钥,然后尝试使用sudo git push之类的命令,那么您将不会使用您生成的相同密钥

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

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

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

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

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

当你试图用不同的用户名推送到存储库时,最简单的解决方案是:

 git remote set-url origin https://USERNAME@github.com/USERNAME/PROJECTNAME.git

我也犯了同样的错误。

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

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