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

相关推荐
BD_Marathon23 分钟前
Ubuntu:Mysql服务器
服务器·mysql·ubuntu
A5资源网1 小时前
cloudflare配合github搭建免费开源影视LibreTV一个独享视频网站 详细教程
github
mortimer1 小时前
从零到一:构建一个 Chatterbox-TTS API 服务
开源·github·ai编程
0wioiw02 小时前
Ubuntu基础(监控重启和查找程序)
linux·服务器·ubuntu
Tipriest_2 小时前
Ubuntu常用的软件格式deb, rpm, dmg, AppImage等打包及使用方法
linux·运维·ubuntu
GBXLUO2 小时前
windows的vscode无法通过ssh连接ubuntu的解决办法
vscode·ubuntu
真智AI2 小时前
利用 Claude Opus 4 自动化 GitHub 工作流:从安装到实战详解
运维·自动化·github
笑衬人心。4 小时前
Ubuntu 22.04 修改默认 Python 版本为 Python3 笔记
笔记·python·ubuntu
寻月隐君6 小时前
Rust 网络编程实战:用 Tokio 手写一个迷你 TCP 反向代理 (minginx)
后端·rust·github
喜欢吃豆7 小时前
快速手搓一个MCP服务指南(九): FastMCP 服务器组合技术:构建模块化AI应用的终极方案
服务器·人工智能·python·深度学习·大模型·github·fastmcp