使用 git 命令登录 github

目录

一、步骤

二、结果

一、步骤:

1⃣️ 检查是否本级是否存在 SSH keys,在命令行终端键入如下命令

$ ls -a ~/.ssh

如果 出现 known_hosts, 则说明要新建一个 SSH key

2⃣️ 创建一个新的 SSH key,在命令行终端键入如下命令

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

注意:-C 后接 github 的账号邮箱

键入此命令后,一直键入回车键 enter 即可

Generating public/private rsa key pair.
Enter file in which to save the key (/home/turf/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again:

3⃣️ 在 github 添加新建的 SSH key

把公钥内容拷贝到 github 的 SSH keys 上

$ vim ~/.ssh/id_rsa.pub

在 github 添加 SSH keys

github -> settings -> SSH and GPG keys -> New SSH key

二、结果

登录 github

$ ssh -T git@github.com
Hi turf96! Youve successfully authenticated, but GitHub does not provide shell access.

如果出现 Youve successfully authenticated, 则说明 git 登录 github 成功了。

经验分享 程序员 微信小程序 职场和发展