macOS配置Github环境 | 2024最新

1. 配置Git全局的用户名和邮箱

1
2
$ git config --global user.name "your name"
$ git config --global user.email "your email like email@example.com"

2. 生成最新的SSH密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ ssh-keygen -t ed25519 -C "email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/me/.ssh/id_ed25519): /Users/me/.ssh/github.key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/me/.ssh/github.key
Your public key has been saved in /Users/me/.ssh/github.key.pub
The key fingerprint is:
SHA256:xxxxxxxxxxxxxxxxx email@example.com
The key's randomart image is:
+--[ED25519 256]--+
| o+o. |
| .. +== |
| =o. Ooo |
| + oo oBEo |
| S .*oo o|
| X =.o o.|
| o = o|
| ... . o. |
| oo.o....o |
+----[SHA256]-----+

3. 访问Github Key设定画面,填写/Users/me/.ssh/github.key.pub的内容,保存SSH keys。

4. 设置SSH连接信息并测试。

1
2
3
4
5
6
7
$ vi ~/.ssh/config
Host github.com
HostName github.com
IdentityFile ~/.ssh/github.key
User git
$ ssh -T github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.