如何在一个电脑上使用两个github账号
2024-10-19 00:21:37
问题描述:公司电脑上默认使用的是公司的github账号,如果希望写一些代码放到个人的github账号上,就需要配置让一个电脑上可以使用两个github账号
原理:管理两个SSH key
1.生成两个SSH KEY
为个人账户生成SSH KEY:
ssh-keygen -t rsa -C "your-self-email-address" -f /c/Users/Administrator/.ssh/id_rsa
为公司github账户生成SSH KEY:
$ ssh-keygen -t rsa -C "your-work-email-address" -f /c/Users/Administrator/.ssh/id_rsa_work
2.分别把id_rsa.pub和id_rsa_work.pub中的内容加到对应github的账号中,添加到Settings的SSH and GPG Keys中
3.把key加到ssh agent上
$ ssh-add ~/.ssh/id_rsa
$ ssh-add ~/.ssh/id_rsa_work
可以通过ssh-add -l来确认结果
4.配置.ssh/config
#one(self-email@.com)
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
User one #two(work-email@xxx.com)
Host github_work.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_work
User two
5.在~/.ssh下运行
$ ssh git@github.com 或者
$ssh git@github_work.com
5.这样github.com对应的是自己的gihub账号,github_work.com对应的是公司的github账号
$ git init
$ git commit -m 'xxxx' #push到github上
$ git remote add origin git@github.com:xxxx/test.git
$git push origin master
最新文章
- delphi 实现最小化系统托盘
- 【转载】Tomcat崩溃事件
- OpenWRT连接OPENVPN的教程
- How I came to find Linux
- wpa_cli调试工具的使用
- 浙江大学PAT上机题解析之1015. 德才论 (25)
- TextView SpannableString 使用之实现可点击超链接效果
- BZOJ 2631: tree [LCT splay区间]
- rabbitmq之基本原理及搭建单机环境
- Android的Activity组件
- Spring Boot 全文搜索引擎 ElasticSearch
- ORA错误总结
- oracle自定义函数返回结果集
- c++中运算符重载
- react缓存问题
- MongoDB 进程控制系列二:结束进程
- 基于CentOS搭建私有云服务
- Git 安装(分布式版本控制系统)
- Bootstrap 网格系统(Grid System)的工作原理 - 媒体查询
- NuGet 让程序集版本变得混乱