Ubuntu 配置 Github 的 SSH keys

先进入已有的 Git 目录或使用新建的一个 Git 仓库下。

设置 Github 用户名和邮箱:

shell 复制代码
$ git config --global user.name [Github用户名]
$ git config --global user.email [Github认证邮箱]

生成 SSH 密钥文件:

shell 复制代码
$ ssh-keygen -t rsa -C [Github认证邮箱]
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): 
[按 Enter 键接受默认文件位置]
Enter passphrase (empty for no passphrase): 
[按 Enter 不设置安全口令, 如果设置, 每次使用 Git 命令时都需要输入]
Enter same passphrase again:
[重复安全口令, 如果上一步没有设置, 按 Enter 跳过]

~/.ssh/ 目录下会创建两个文件:

  • id_rsa: 私钥文件
  • id_rsa.pub: 公钥文件

将公钥文件内容打印后复制:

shell 复制代码
$ cat ~/.ssh/id_rsa.pub

登陆 Github 点击 右上角头像 -> Settings -> SSH and GPG keys -> New SSH key 输入以下内容:

  • Title: 任意取名
  • Key type: Authentication Key
  • Key: 复制上一步中的公钥文件内容到此处

点击 Add SSH key 完成创建, 验证 Authentication 是否正常:

shell 复制代码
$ ssh -T git@github.com
The authenticity of host 'github.com (0.0.0.0)' can't be established.
ED25519 key fingerprint is SHA256:+xxxxxxxxx/xxxxxxxxx.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? 
[选择 yes 使服务器的连接信息保存在系统中]
Warning: Permanently added 'github.com' (ED0000) to the list of known hosts.
Hi [Github用户名]! You've successfully authenticated, but GitHub does not provide shell access.

最后输出 Hi [Github用户名]! You've successfully authenticated, but GitHub does not provide shell access. 就表示配置成功了。

相关推荐
阿里嘎多学长8 小时前
2026-09-09 GitHub 热点项目精选
开发语言·程序员·github·代码托管
面包狗AI4S9 小时前
GitHub AI4S 项目观察(2026-08-28—2026-09-03)
github
GoGeekBaird9 小时前
从「跑完即销毁」到「用完再销毁」:云沙箱的一次进化
后端·github·ai编程
逛逛GitHub12 小时前
GitHub 又一个 3D 人体可视化项目,AI 能力提升催生新场景。
github
峰向AI12 小时前
多代理协作的正确姿势:Atlas让 Claude Code 和 Codex共享记忆
github
蜡台13 小时前
GitHub 关闭 Two‑factor authentication(2FA)
github
事圆则缓13 小时前
Ubuntu 安装与配置 Samba 服务器
linux·服务器·ubuntu
乌恩大侠14 小时前
【Sionna】docker build ubuntu cuda
ubuntu·docker·容器·spark·o-ru·ai-ran
HaipengYu15 小时前
Star History 凉凉?5 分钟部署一套属于自己的 GitHub 星标统计服务
github
理智.62915 小时前
Git 工具使用之项目版本回退与修改备份:stash、reset、reflog 常用指令详解
git·gitee·github