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


当前回答

在你的电脑的任何地方新建一个文件夹(比如在桌面上) 移动到新文件夹,打开git bash。

&在bash中编写以下代码:

$ git init $ git远程添加原点https://github.com/YOUR_GITHUB_HANDLER/YOUR_REPO_NAME.git $ git拉源主

(无论文件是否被拉出,都要查看新文件夹)

如果文件被删除,则首先删除旧文件夹(发生上述错误的文件夹)中的所有文件/文件夹,包括.git文件夹

&从新文件夹中复制所有文件,包括.git,并将其粘贴到出现上述错误的旧文件夹中。

这将为您获取远程回购。

如果你想获取远程回购而不删除你在本地所做的新更改,那么只需要复制并粘贴我们的新.git文件夹

现在你可以使用$ git push origin master了

其他回答

在GitHub中使用终端添加RSA密钥:

MAC:

进入Users/ xxxx /.ssh文件夹 执行命令:cd ~/。ssh && ssh-keygen -t ed25519 -C "github_email@id.com" 输入文件名为id_rsa 输入if ask口令 再次输入 运行eval "$(ssh-agent -s)" 打开配置文件:Open ~/.ssh/config 如果不存在,则创建为: 触碰~ / . ssh / config 现在打开配置文件,并在文件中添加以下行:

主机* AddKeysToAgent是的 UseKeychain是的 IdentityFile ~ / . ssh / id_rsa

关闭文件 为agent run命令添加ssh私钥。 ssh-add -K ~/.ssh/id_rsa . sh 现在复制ssh密钥为: Pbcopy < ~/.ssh/id_rsa.pub 去gitHub/BitBucket 点击管理帐户 点击SSH键 删除现有密钥 点击添加键 粘贴复制的密钥。

我正与同样的问题作斗争,这就是我所做的,我能够克隆回购。我在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.

视觉指南(Windows)

1 / 2。Git批处理端

1.1. 打开git批处理(下载她)

1.2. 粘贴下面的文本(更改到您的GitHub帐户电子邮件)

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

1.3. 按Enter(接受默认文件位置)

1.4. 单击Enter两次(或设置SSH密钥passphrases - Gitbub passphrases docs)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

1.5. 键生成:

您的身份信息已保存在/c/Users/user/.ssh/id_rsa…

1.6. 将SSH密钥复制到剪贴板。

$ clip < ~/.ssh/id_rsa.pub

2 / 2。Github网站用户端

在用户设置下

SSH和GPG密钥=>新的SSH密钥:

粘贴步骤1.6中的代码

:完成)


如果有人不想使用SSH,请使用HTTPS:

Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

最简单的方法之一

〇前往终点站

  git push <Git Remote path> --all

对我来说,问题是使用sudo:

sudo git克隆git@github.com:userName/repo.git导致上述错误。

所以为了解决这个问题,我咀嚼了我试图克隆到的文件夹

sudo chown -R $USER:$USER /var/www/iqge.org/html

然后用这个 git克隆git@github.com:userName/repo.git was successfully done