美文网首页
如何在mac系统上连接git和github

如何在mac系统上连接git和github

作者: 天永 | 来源:发表于2018-12-04 16:25 被阅读0次

1.在mac系统使用HomeBrew安装git (如果没有git)

直接使用命令行brew install git 

2.检查是否有ssh keys

终端命令行 cd ~/.ssh  (一般git的公钥秘钥相关的文件都会保存在.ssh文件里面)

3.如果有.ssh文件。

那就说明本地的git连接过其他远程仓库(可能是之前主人的)。那么你最好创建一个新的ssh key 并保存好前主人的ssh key(这是品质)

ls命令行后会看到三个文件,分别是

id_rsa     id_rsa.pub   known_hosts

mkdir  key_backup(创建一个新文件夹用于保存旧的id_rsa)

cp id_rsa* key_backup(移动旧的key文件,就是id_rsa到key_backup文件夹)

rm  id_rsa*(删除旧的,已经备份了,接下来创建你的)

ssh-keygen -t rsa -C "youremail@youremail.com"(输入你绑定github账号的邮箱)

随后输出一下语句:

Generating public/private rsa key pair. Enter file in which to save thekeys (/Users/your_user_directory/.ssh/id_rsa): //这里需要按下 enter 键就好

按下 enter 之后,又会出现下面的提示:

//输入回车后提示输入一个类似于密码的自定义的通行证号,如果直接回车则为空

Enter passphrase(empty for no passphrase):

//提示重新输入以便确认输入是否正确

Enter same passphraseagain:

随后,你会收到一大串的提示,大概的意思是告诉你创建好了 id_rsa 和 id_rsa.pub 文件。

4.在github上添加你的ssh key

在github中添加ssh(如图示):

登陆github,选择Settings-->SSH Keys (点击New SSH key)

Title:xxxxx@gmail.com

Key:打开你生成的id_rsa.pub文件(可以使用cat id_rsa.pub命令行,查看相应里面的字符串,复制,全部都是),将其中内容拷贝至此。创建成功会有相应的提示。

5.验证是否连接github

终端命令行 ssh -T git@github.com,会显示以下信息:

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.

然后就大功告成了

相关文章

网友评论

      本文标题:如何在mac系统上连接git和github

      本文链接:https://www.haomeiwen.com/subject/llxvcqtx.html