首先来设置使用 Git 时的姓名和邮箱地址。名字请用英文输入。git
$ git config --global user.name "Firstname Lastname" $ git config --global user.email "your_email@example.com"
这个命令,会在“~/.gitconfig”中以以下形式输出设置文件。程序员
[user] name = Firstname Lastname email = your_email@example.com
想更改这些信息时,能够直接编辑这个设置文件。这里设置的姓名 和邮箱地址会用在 Git 的提交日志中。因为在 GitHub 上公开仓库时,这里的姓名和邮箱地址也会随着提交日志一同被公开,因此请不要使用不便公开的隐私信息。github
在 GitHub 上公开代码后,前来参考的程序员可能来自世界任何地方,因此请不要使用汉字,尽可能用英文进行描述。固然,若是您不想使用真名,彻底能够使用网络上的昵称。shell
GitHub 上链接已有仓库时的认证,是经过使用了 SSH 的公开密钥认证方式进行的。如今让咱们来建立公开密钥认证所需的 SSH Key,并将其添加至 GitHub。网络
运行下面的命令建立 SSH Key。dom
$ ssh-keygen -t rsa -C "your_email@example.com" Generating public/private rsa key pair. Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa): 按回车键(必定按回车,不要乱输入任何内容,不然后面配置会 出问题) Enter passphrase (empty for no passphrase): 输入密码 Enter same passphrase again: 再次输入密码
“your_email@example.com”的部分请改为您在建立帐户时用的邮箱地址。密码须要在认证时输入,请选择复杂度高而且容易记忆的组合。 输入密码后会出现如下结果。ssh
Your identification has been saved in /Users/your_user_directory/.ssh/id_rsa. Your public key has been saved in /Users/your_user_directory/.ssh/id_rsa.pub. The key fingerprint is: fingerprint值 your_email@example.com The key's randomart image is: +--[ RSA 2048]----+ | .+ + | | = o O . | 略
id_rsa 文件是私有密钥,id_rsa.pub 是公开密钥。ide
在 GitHub 中添加公开密钥,从此就能够用私有密钥进行认证了。spa
点击右上角的帐户设定按钮(Account Settings),选择 SSH Keys 菜 单。点击 Add SSH Key 以后,会出现以下图的输入框。在 Title 中输入适当的密钥名称。Key 部分请粘贴 id_rsa.pub文件里的内容。id_rsa.pub 的内容能够用以下方法查看。日志
添加成功以后,建立帐户时所用的邮箱会接到一封提示“公共密钥添加完成”的邮件。 完成以上设置后,就能够用手中的私人密钥与 GitHub进行认证和通讯了。
ssh -T git@github.com The authenticity of host 'github.com (207.97.227.239)' can't be established. RSA key fingerprint is fingerprint值 . Are you sure you want to continue connecting (yes/no)? 输入yes
出现以下结果即为成功
Hi hirocastest! You've successfully authenticated, but GitHub does not provide shell access.