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

相关推荐
鸣弦artha35 分钟前
TabBar标签页组件详解
linux·git·ubuntu
17(无规则自律)2 小时前
【CSAPP 读书笔记】第一章:计算机系统漫游
linux·c语言·arm开发·嵌入式硬件·学习·ubuntu
Lam㊣2 小时前
Ubuntu(Ubuntu 22.04.4 LTS)更改IP地址及网关
tcp/ip·ubuntu·php
Sheep Shaun3 小时前
Linux 环境搭建终极指南(Ubuntu 版):2026 最新版,适配 Ubuntu 24.04 LTS
linux·运维·服务器·ubuntu
TTGGGFF4 小时前
告别繁琐命令行:自研多线程 SSH 极速文件传输助手(附 GitHub 源码)
运维·ssh·github
小林up4 小时前
Ubuntu访问不了Git解决办法
linux·git·ubuntu
郭涤生4 小时前
H264 NALU详解
ubuntu
小林up4 小时前
Ubuntu使用阿里云安装docker
ubuntu·阿里云·docker
林深现海4 小时前
宇树 Go2 + NaVILA 全栈导航系统详解 (新手入门版)
linux·vscode·yolo·ubuntu·机器人
林深现海5 小时前
基于宇树 Go2 与 NaVILA 的全栈视觉导航系统深度解析
linux·vscode·yolo·ubuntu·机器人