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. 就表示配置成功了。

相关推荐
逛逛GitHub20 小时前
飞书多维表“独立”了!功能强大的超出想象。
人工智能·github·产品
努力的小雨1 天前
混元开源之力:spring-ai-hunyuan 项目功能升级与实战体验
后端·github
NocoBase1 天前
GitHub 上 Star 数量前 10 的开源项目管理工具
开源·github·资讯
绝无仅有1 天前
面试实战总结:数据结构与算法面试常见问题解析
后端·面试·github
绝无仅有1 天前
Docker 面试常见问题及解答
后端·面试·github
逛逛GitHub2 天前
斩获 2 万多 Star!国外老哥把全网 n8n 工作流都开源了
github·工作流引擎
杨杨杨大侠2 天前
Atlas Mapper 案例 01:初级开发者 - 电商订单系统开发
java·开源·github
绝无仅有2 天前
后端 Go 经典面试常见问题解析与总结
后端·面试·github
绝无仅有2 天前
后端工程师面试常见问题与回答解析总结
后端·面试·github
逛逛GitHub3 天前
发现一个 AI 大模型服务质量榜单。
github