尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

服务器和GitHub密钥配对

服务器和GitHub密钥配对 完整解决步骤1. 生成 SSH 密钥对root 用户执行把邮箱换成你绑定 GitHub 的注册邮箱ssh-keygen -t ed25519 -C 你的GitHub注册邮箱一路回车即可密钥存储路径默认/root/.ssh/id_ed25519不需要设置密钥密码直接回车两次老旧系统没有 ed25519 就用 RSAssh-keygen -t rsa -b 4096 -C 你的GitHub邮箱2. 查看公钥内容并复制cat /root/.ssh/id_ed25519.pub # RSA版本用cat /root/.ssh/id_rsa.pub输出一长串以ssh-ed25519/ssh-rsa开头、末尾带邮箱的字符串完整全选复制3. GitHub 网页添加公钥打开 GitHub 头像 → Settings → SSH and GPG keys点击 New SSH keyTitle 随便填例如服务器 Linux-rootKey 粘贴刚才复制的全部公钥内容 → Add SSH key4. 修改 ssh 配置文件适配 443 端口编辑 ssh 配置vim /root/.ssh/config写入下面内容区分密钥类型用 ed25519 密钥推荐Host github.com HostName ssh.github.com User git Port 443 IdentityFile ~/.ssh/id_ed25519RSA 密钥用这个Host github.com HostName ssh.github.com User git Port 443 IdentityFile ~/.ssh/id_rsa保存退出设置权限必须否则 ssh 报错chmod 600 /root/.ssh/config chmod 700 /root/.ssh5. 测试连通ssh -T gitgithub.com出现提示Hi 你的用户名! Youve successfully authenticated, but GitHub does not provide shell access.代表 SSH 连接 GitHub 成功。后续仓库使用拉取、推送代码依旧正常使用 ssh 地址git clone gitgithub.com:xxx/xxx.git
返回列表