1-1 Mac Git下载与环境配置

Git安装

有两种方法:

(1)在https://git-scm.com/download 下载 git的dmg镜像。

(2)用homebrew指令下载,不过首先需要安装homebrew ,在终端执行后面指令安装,homebrew /usr/bin/ruby -e "$(curl -fsSL              https://raw.githubusercontent.com/Homebrew/install/master/install)"
完成后,使用以后指令安装Git,brew install git

安装好Git后,配置用户名和用户邮箱,以后每次与Git的交互都会使用该信息。

git config --global user.name "your_name"  
git config --global user.email "[email protected]"

引号里写用户名和邮箱地址。

生成密钥

Git关联远端仓库时候需要提供公钥,本地保存私钥,每次与远端仓库交互时候,远端仓库会用公钥来验证交互者身份。使用以下指令生成密钥。

1.检查SSH key

     cd ~/.ssh

2.备份已有的key,(如果有的话)

     mkdir key_backup

     mv id_rsa* key_backup

3.生成SSH key

ssh-keygen -t rsa -C "[email protected]"

ssh-keygen -t rsa -C "[email protected]"

敲回车会出现以下信息

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/shawn/.ssh/id_rsa):
Created directory '/Users/shawn/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/shawn/.ssh/id_rsa.
Your public key has been saved in /Users/shawn/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:JFXhJ74mcCzfCEzIQ80G58A0VexDfwSMaW8GdWAs4nk [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|   o*=oooBB+.    |
|   o.*=.Ooo..    |
|    +o+*.=o..    |
|     +o+E.=o.    |
|      =.S+..     |
|       * o .     |
|        + +      |
|         o       |
|                 |
+----[SHA256]-----+

4.将SSH key添加到GitHub

登录到GitHub页面,Account Settings->SSH Public Keys->Add another key

  • 控制台输入cd指令,进入当前用户目录
  • 输入ls -a指令,查看当前用户目录下所有文件,包括隐藏文件
  • 输入cd .ssh指令,进入.ssh目录
  • 输入ls指令,查看.ssh目录下的文件
  • 输入cat id_rsa.pub指令,查看id_rsa.pub文件中内容

将生成的key(id_rsa.pub文件)内容copy到输入框中,save。

5.测试链接

$ ssh [email protected]

会出现以下信息

ShawndeMacBook-Pro:.ssh shawn$ ssh -T [email protected]
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi ShawnJing128! You've successfully authenticated, but GitHub does not provide shell access.

出现上述提示信息说明连接成功(github并不提供shell登陆但已经连接成功)

你可能感兴趣的:(Git)