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

相关推荐
字节幺零二四33 分钟前
累计下载 3000+!我的自制实用工具合集现已同步至 GitHub
github·局域网·转换·传输·字幕
oMcLin43 分钟前
如何在Ubuntu 20.04系统的香港服务器上使用Docker搭建高效的CI/CD流水线并集成Kubernetes?
服务器·ubuntu·docker
爱吃大芒果1 小时前
openJiuwen在Ubuntu上的安装教程
linux·运维·ubuntu
oMcLin2 小时前
如何在Ubuntu 22.04上通过配置LVM优化存储,提升香港服务器的大规模数据库的读写性能?
服务器·数据库·ubuntu
oMcLin2 小时前
如何在 Ubuntu 22.04 服务器上搭建并优化 Elasticsearch 集群,支持实时日志分析
服务器·ubuntu·elasticsearch
HABuo2 小时前
【Linux进程(二)】操作系统&Linux的进程状态深入剖析
linux·运维·服务器·c语言·c++·ubuntu·centos
知识分享小能手2 小时前
Ubuntu入门学习教程,从入门到精通, Ubuntu 22.04中的C/C++编程(18)
c语言·学习·ubuntu
鸠摩智首席音效师2 小时前
如何在 Ubuntu / Debian 上挂载 Amazon S3 Buckets ?
服务器·ubuntu·debian
感觉不怎么会2 小时前
ubuntu - 设备常见指令
linux·服务器·ubuntu
HIT_Weston11 小时前
84、【Ubuntu】【Hugo】搭建私人博客:文章目录(三)
linux·运维·ubuntu