Jalena Blog

  • 首页
  • 程序开发
    • Java
    • Spring
    • SpringBoot
    • SpringMvc
    • Python
    • Odoo
    • C#
    • SQL
    • Web
    • Linux
  • 移动设备
    • Android
    • Router
  • 杂七杂八
    • 我的废话
    • 音频
    • 视频
    • 常用软件
  • 关于
  1. 首页
  2. 杂七杂八
  3. 正文

Git 使用密钥登陆服务

2017-10-25

生成密钥

ssh-keygen -m PEM -t ed25519 -C "your.email@example.com"  # 创建新的 SSH 私钥与公钥秘钥对,输入你的邮箱作为标签
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]  # 推荐使用默认地址
Enter passphrase (empty for no passphrase):  # 此处直接回车即可;若设置密码,则每次使用 SSH 方式推送代码时都会要求输入密码

# 生成 rsa 密钥
# 在OpenSSH 8.8中已默认禁用 ssh-rsa 方式,因此建议使用 ed25519 
ssh-keygen -t rsa -C "jalena@bcsytv.com"

密钥管理

不管在Windows还是Linux下,均可以使用~/.ssh/config来配置密钥的管理

vim ~/.ssh/config

Host git*
HostName %h
IdentityFile %d/.ssh/id_rsa

Host e.coding.net
HostName %h
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
IdentityFile %d/.ssh/git_rsa

Host codeup*
HostName %h
IdentityFile %d/.ssh/git_rsa
关于Rsa禁用

因OpenSSH8.8已经默认禁用ssh-rsa,所以在使用rsa方式的密钥时,需要为其手动开启ssh-rsa,参考上面的e.coding.net配置

Windows

将密钥文件存放至用户目录 ~\.ssh

Windows 存放密钥

使用密钥登陆必须使用git@这样的ssh协议才行,如果之前使用的是https协议的话,那么需要将协议修改为git@这样的ssh协议。

Mac & Linux

在Linux或Unix环境下,我们只需要将私钥文件放置到~/.ssh目录下即可。

因Linux环境对文件权限的控制与Windows存在不同,所以你还需要使用chmod为起设置权限。

修改仓库地址

$ git remote -v
origin https://github.com/demo/test.git (fetch)
origin https://github.com/demo/test.git (push)

# 替换协议为git
$ git remote set-url origin git@github.com:demo/test.git

添加密钥至GitEE

gitee 公钥设置

添加密钥至GitHub

测试

$ ssh -T git@gitee.com
Welcome to Gitee.com, jalena!

$ ssh -T git@github.com
Hi jalena! You've successfully authenticated, but GitHub does not provide shell access.

至此可以使用git@来管理项目

标签: git
最后更新:2022-04-28

Jalena

原创内容,转载请注明出处! 部分内容来自网络,请遵守法律适用!

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

【腾讯云】云服务器特惠热卖中
文章目录
  • 生成密钥
  • 密钥管理
    • Windows
    • Mac & Linux
    • 修改仓库地址
    • 添加密钥至GitEE
    • 添加密钥至GitHub
    • 测试
标签聚合
java Centos odoo 其他 生活 wordpress docker MySql
分类
  • Android / 4篇
  • C# / 10篇
  • Codec / 9篇
  • Conversion / 14篇
  • Editing / 16篇
  • Java / 47篇
  • Javascript / 3篇
  • Linux / 30篇
  • Odoo / 25篇
  • Python / 6篇
  • SQL / 30篇
  • Web / 3篇
  • Windows / 4篇
  • 我的日记 / 10篇
  • 杂七杂八 / 93篇
  • 软件开发 / 72篇
  • 非线性编辑 / 1篇

COPYRIGHT © 2026 Jalena Blog. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蜀ICP备17025376号