Git 用户名、邮箱配置
$ git config --global user.name "xxxx"
$ git config --global user.email "xxxx@xxxx.xxx"
编辑完成后,在 User 目录下,可以看到 .gitconfig
文件。里面包含有 git 配置信息。如下:
$ ls -al .gitconfig
-rw-r--r-- 1 Jack staff 526 Sep 11 09:28 .gitconfig
$ cat .gitconfig
[core]
excludesfile = /Users/jack/.gitignore_global
[user]
name = xxxx
email = xxxx@xxxx.xxx
SSH 密钥配置
$ cd ~/.ssh
$ ls
authorized_keys github_rsa github_rsa.pub id_rsa id_rsa.pub known_hosts
初识情况下,ssh 目录下没有 id_rsa
与 id_rsa.pub
文件。这时候可以执行以下命令生成该文件。
$ ssh-keygen -t rsa -C "xxxx@xxxx.xxx"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jack/.ssh/id_rsa):
/Users/jack/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/jack/.ssh/id_rsa.
Your public key has been saved in /Users/jack/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0cLyHA/lh3QqQc5olWsvctjVMRJjPZbCsREuXvZnIlo xxxx@xxxx.xxx
The key's randomart image is:
+---[RSA 2048]----+
| .+oX=.. |
| *.O+BB |
| + @.X=.+ |
| . =o@.o. |
| +SoE o o |
| o +o.. + |
| o.. |
| |
| |
+----[SHA256]-----+
最后,ssh 密钥生成了。使用 cat 命令查看密钥
$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDokhmZsm0SUJUnfcutfogQ6OsAfA29yvN/ePbsdBOIn+/BB6uGP8nR0PbIx/P1OO+trDvBmcaIwxUJ2/pL6P317/xxxxx+tctor+138eBmJdEECD7r/+gK+Xcd5slPt6Y4gYf5ahgTaLNl1mt5OsYFdi3VWsa+JmWbf+UGIgOXy/M5F24FBBf2Ni2Ko2G1ehFkrH3MydeOFc2iuPCLZj7VrFZjtgBfMi7hvKy5F8ToXw67OGkJqi5bKF55vi5iqQw6h285HEa6EaGV xxx@xxxx
添加 ssh 公钥到 github 上。后使用以下命令检验是否正常工作:
$ ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
当出现 xxx 的时候,你已经访问 github 成功了。ps: xxx 是你的用户名
网友评论