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


当前回答

伙计们我是这么干的

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之类的命令,那么您将不会使用您生成的相同密钥

其他回答

Mac操作步骤:

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

在我的ubuntu系统中,我按照下面的步骤解决了这个问题。因为我正在尝试用无密码ssh到系统。

sudo vi /etc/ssh/sshd_config

1)评论如下: #更改为no禁用隧道明文密码 # PasswordAuthentication是的 PasswordAuthentication no ---->注释此。

2)然后重新启动sshd守护进程,如下所示。

重启SSHD服务

除了Rufinus的回复,在Windows中将ssh密钥复制到剪贴板的快捷方式是:

id_rsa类型。Pub |剪辑

参考文献:

打印到标准输出 复制命令行输出到剪贴板

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

我必须将ssh密钥复制到根文件夹。 谷歌云计算引擎,Ubuntu 18.04

sudo cp ~/.ssh/* /root/.ssh/