github 用 SSH + 配好密钥(自动免密登录)

如果你是在 Linux 上操作,添加 GitHub SSH 登录同样适用,以下是完整的 Linux 下 GitHub SSH 登录配置流程(适配 Ubuntu / CentOS / Debian 等系统):
🧰 一、生成 SSH 密钥对(如果还没有)

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

说明:

-t rsa 表示生成 RSA 类型密钥。

-b 4096 是密钥长度。

-C 是注释(通常用邮箱)。

连续回车即可(默认保存在 ~/.ssh/id_rsa)。
🧾 二、查看公钥内容

cat ~/.ssh/id_rsa.pub

复制输出的整行文本(一般以 ssh-rsa 开头)。
🌐 三、登录 GitHub 添加 SSH 公钥

打开网页 https://github.com

登录账号

点击右上角头像 → Settings(设置)

左侧点击 SSH and GPG keys

点击右上角 New SSH key

填写 Title(自定义,如“Linux服务器”)

粘贴刚才复制的公钥

点击 Add SSH key

🧪 四、测试连接是否成功

ssh -T git@github.com

首次连接会提示:


The authenticity of host 'github.com (IP)' can't be established...
Are you sure you want to continue connecting (yes/no)?

输入:

yes

如果一切正确,会显示:

Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.

✅ 步骤 6(可选):避免 Git 默认使用 https 地址

你可以全局设置 Git 优先使用 ssh:

git config --global url."git@github.com:".insteadOf "https://github.com/"

0

版权声明 ▶ 本网站名称:我的学习笔记
▶ 本文链接:https://ooolo.net/article/623.html
▶ 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行核实删除。
▶ 转载本站文章需要遵守:商业转载请联系站长,非商业转载请注明出处!!!

none
最后修改于:2025年06月05日 15:24

添加新评论

icon_mrgreen.pngicon_neutral.pngicon_twisted.pngicon_arrow.pngicon_eek.pngicon_smile.pngicon_confused.pngicon_cool.pngicon_evil.pngicon_biggrin.pngicon_idea.pngicon_redface.pngicon_razz.pngicon_rolleyes.pngicon_wink.pngicon_cry.pngicon_surprised.pngicon_lol.pngicon_mad.pngicon_sad.pngicon_exclaim.pngicon_question.png