git多账户管理笔记

git

多账户管理

参考:https://io-oi.me/tech/ssh-with-multiple-github-accounts/

参考:https://www.cnblogs.com/popfisher/p/5731232.html

  1. 生成github.com对应的私钥公钥
"""
ssh-keygen:参数
–b bits
指定要创建的密钥的位数。最小位数为 512 位。通常,2048 位足以满足安全需要。密钥大小超过该值并不会提高安全性,反而会降低速度。缺省值为 2048 位。
 
–t type
指定用于生成密钥的算法,其中 type 是 rsa、dsa 和 rsa1 中的一种。rsa1 类型仅用于 SSHv1 协议。
 
–R hostname
从 known_hosts 文件中删除属于 hostname 的所有密钥。此选项可用于删除散列主机。请参见 –H。
"""
# 帐号一
$ ssh-keygen -t rsa -b 4096 -C "1412686627@qq.com"

Generating public/private rsa key pair.
Enter file in which to save the key (/home/archie/.ssh/id_rsa): id_rsa_yangyang188  # 起别名 

# 帐号二
$ ssh-keygen -t rsa -b 4096 -C "2633316793@qq.com"

Generating public/private rsa key pair.
Enter file in which to save the key (/home/archie/.ssh/id_rsa): id_rsa_zhihuya188  # 起别名
  1. .ssh目录创建config文本文件并完成相关配置

vim ~/.ssh/config编辑如下内容:

# 自行修改 host 和 IdentityFile
host yangyang188.github.com
    Hostname github.com
    User git
    IdentityFile /c/Users/8/.ssh/id_rsa_yangyang188

host zhihuya188.github.com
    Hostname github.com
    User git
    IdentityFile /c/Users/8/.ssh/id_rsa_zhihuya188

Host的名字可以取为自己喜欢的名字,不过这个会影响git相关命令,例如:

Host mygithub 这样定义的话,命令如下,即git@后面紧跟的名字改为mygithub

git clone git@mygithub:PopFisher/AndroidRotateAnim.git

  1. 打开Git Bash客户端(管理员身份运行)执行测试命令测试是否配置成功(会自动在.ssh目录生成known_hosts文件把私钥配置进去)
ssh -T git@[host]
  1. 连接远程库
# 帐号一
 git remote set-url origin git@yangyang188.github.com:yangyang188/git_test.git

# 帐号二
 git remote set-url origin git@zhihuya188.github.com:zhihuya188/zhihuya188.github.io.git
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值