github add SSH key

0x00

Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit.

每次 clone 私人项目或者 push 都要输入用户名密码?试试 ssh 吧。

0x01

  • 查看 ~/.ssh 目录下是否已经有密钥
1
$ ls -al ~/.ssh
  • 生成 ssh key
1
2
3
4
$ ssh-keygen -t rsa -C "xxx@xxx.xxx" # 可以写上自己的邮箱

# -t 指定密钥类型,默认是 rsa ,可以省略。
# -C 设置注释

📝生成过程中会出现内容,建议直接回车默认设置

1
2
3
4
5
6
7
8
9
10
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxx/.ssh/id_rsa): [Press enter]
# 设置密码 也可以直接回车
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
# 生成完成
Your identification has been saved in /c/Users/you/.ssh/id_rsa.
Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
The key fingerprint is:
f4:3b:xx:85:d6:xx:f0:68:xx xxx@xxx.xxx
  • 等待生成完成后,到 github 上添加 ssh key

settings->ssh and gpg keys->new ssh key

1
cat ~/.ssh/id_rsa.pub

⚠️When copying your key, don’t add any newlines or whitespace. 不要加空格或者换行,否则会添加失败

填写相关内容

  • 最后测试连接
1
ssh -T git@github.com

如果出现一串字符让你输入 (yes/no) 则直接输入 yes 回车即可

1
2
# 成功之后大概是这样子
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

以后就使用 ssh 连接进行 clone or push 吧🍻

0x02

封面出处:http://simpledesktops.com/browse/desktops/2019/mar/04/zurich-skyline/

Author: ronething
Link: https://blog.ronething.cn/20170926-ssh.html
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.