不知道什么原因,CSDN博客保存的时候会丢失图片和格式,请可以戳这里到我有道云笔记分享
今天特地把Github上的教程Github Generating SSH keys翻译成中文(并非全文翻译),因为自己的水平有限,有错误还请指出。
首先,需要检查你的电脑上是否存在SSH keys,打开你的电脑终端,输入以下命令:
ls -al ~/.ssh # Lists the files in your .ssh directory, if they exist
要生成新的SSH密钥,打开终端输入以下命令,并确输入你的E-mail。默认设置是首选,因此当系统会提示“请输入要保存的重要文件:”你,只需按Enter键继续就可以了。
ssh-keygen -t rsa -C "your_email@example.com" # Creates a new ssh key, using the provided email as a label # Generating public/private rsa key pair. # Enter file in which to save the key (/home/you/.ssh/id_rsa):
接下来要求你输入密码,这个密码是使用SSH链接 push的时候用的,可以选择设,如果不想设 按Enter就可以了
然后如果输出下面内容,表示key创建成功。# Your identification has been saved in /home/you/.ssh/id_rsa. # Your public key has been saved in /home/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
接下来把你刚刚创建的key添加到ssh-agent,执行以下两条命令。
# start the ssh-agent in the background eval "$(ssh-agent -s)" # Agent pid 59566 ssh-add ~/.ssh/id_rsa
运行如下命令,拷贝key到剪切板. key的文件名是 id_dsa.pub
, id_ecdsa.pub
id_ed25519.pub
. 或者直接用gedit等编辑器打开这些文件复制即可。
sudo apt-get install xclip # Downloads and installs xclip. If you don‘t have `apt-get`, you might need to use another installer (like `yum`) xclip -sel clip < ~/.ssh/id_rsa.pub # Copies the contents of the id_rsa.pub file to your clipboard
然后打开你github设置页面,里面有个SSH keys
然后点击Add SSH key
为了确保一切工作正常,可以测试一下是否可以正常链接到github上。测试时,可能会让你输入密码,
打开你的终端,然后输入:
ssh -T git@github.com # Attempts to ssh to github
你可能会看到这样的错误信息:
... Agent admitted failure to sign using the key. debug1: No more authentication methods to try. Permission denied (publickey).
可参阅帮助文章。
您可能会看到这样的警告:
# The authenticity of host ‘github.com (207.97.227.239)‘ can‘t be established. # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. # Are you sure you want to continue connecting (yes/no)?
不用担心,这是正常的。直接输入“yes”。
# Hi username! You‘ve successfully authenticated, but GitHub does not # provide shell access.
如果该用户名是你的,你已经成功设置SSH密钥!
如果仍然无法链接到github,你可以参考这些文章。
如果你从HTTPS切换到SSH,你现在需要更新远程存储库的URL。欲了解更多信息,请参见更改远程的URL。
原文地址:http://blog.csdn.net/xindoo/article/details/40181087