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

相关推荐
Web极客码20 分钟前
在Ubuntu 20.04的服务器上查找的服务器的IP地址
服务器·tcp/ip·ubuntu
cxr8281 小时前
Claude Code PM 深度实战指南:AI驱动的GitHub项目管理与并行协作
人工智能·驱动开发·github
FL16238631291 小时前
[ubuntu][C++]onnxruntime安装cpu版本后测试代码
linux·c++·ubuntu
逻辑羊驼1 小时前
VSCode+MobaXterm+X11可视化界面本地显示
运维·服务器·ubuntu·3d
金融数据出海4 小时前
黄金金融期货数据API对接技术文档
开发语言·金融·github
hfd19905 小时前
GitHub 宕机自救指南:保障开发工作连续性
github
云的牧人5 小时前
Ubuntu 22 redis集群搭建
linux·运维·ubuntu
小猪写代码6 小时前
Ubuntu 文件权限管理
linux·ubuntu
绝无仅有7 小时前
未来教育行业的 Go 服务开发解决方案与实践
后端·面试·github
jzzy_hony9 小时前
移植Qt4.8.7到ARM40-A5
qt·ubuntu·arm·终端