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

相关推荐
徒劳爱学仙2 小时前
全志 V821 韦东山 Avaota-F1-B ubuntu开发环境搭建
linux·运维·ubuntu
jingleli216 小时前
ssh配置内置sftp并使用密钥对登录
运维·ssh
ReSearch6 小时前
sfsEdgeStore:边缘计算时代的轻量级数据存储解决方案
数据库·后端·github
irpywp7 小时前
平台禁下载、格式不兼容、剪辑太麻烦,Media Downloader:mac 原生媒体下载工具,一站式解决视频下载、转码、裁剪、管理难题
macos·开源·github·音视频·媒体
勤自省7 小时前
ROS2从入门到“重启解决”:21讲8~12章踩坑血泪史与核心总结
linux·开发语言·ubuntu·ssh·ros
全球通史8 小时前
Jetson Nano语音交互:本地大模型全链路实战
ubuntu·交互
酿情师8 小时前
FinalShell 下载与安装指南
linux·服务器·windows·ssh
Harvy_没救了9 小时前
【github 爆款】隐匿与通行:CloakBrowser 项目深度洞察报告
github
L_Xian10 小时前
StarrySky重新维护了,摆烂了一段时间,想想还是搞搞吧。
android·github·音视频开发
风起时Funchs10 小时前
我把 JetBrains 的 Git 客户端搬到了 VS Code
github