虽然我们建议HTTPS的,因为它通常更容易设置,您还可以使用SSH密钥来建立你的电脑和GitHub上之间的安全连接。以下步骤将指导您完成生成SSH密钥,然后添加公钥到您的GitHub上的帐户。
cd ~/.ssh ls # Lists the files in your .ssh directory
检查清单,看看是否有一个命名为文件的目录的id_rsa.pub
和id_dsa.pub中
。如果你没有任何这些文件转到步骤2。否则,你已经有一个现有的密钥对,你可以直接跳到第3步。
要生成新的SSH密钥,输入下面的代码。我们希望默认设置,所以当要求输入要保存的密钥文件,只需按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 (/c/Users/you/.ssh/id_rsa): [Press enter] ssh-add id_rsa
现在,你需要输入一个密码。
Enter passphrase (empty for no passphrase): [Type a passphrase] # Enter same passphrase again: [Type passphrase again]
这应该给你的东西是这样的:
Your identification has been saved in /c/Users/you/.ssh/id_rsa. # Your public key has been saved in /c/Users/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
运行下面的代码到密钥复制到剪贴板。
clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
为了确保一切工作现在你的SSH到GitHub上。当你这样做,你将被要求使用密码,这对于这个目的是先前创建的口令来验证此操作。不要更改git@github.com
一部分。这应该在那里。
ssh -T git@github.com # Attempts to ssh to github
您可能会看到这样的警告:
# 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)?
不要担心,这是应该发生的。验证指纹的一个在这里比赛,然后键入“是”。
# Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
如果用户名是正确的,你已经成功地建立了你的SSH密钥。不要担心shell访问的事情,你不希望出现这种情况呢。