Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 1.37 KB

一台设备多个git账号.md

File metadata and controls

67 lines (52 loc) · 1.37 KB

一台设备多个 git 账号

取消全局用户信息

# 通过以下语句查看设置的账户信息
$ git config --global user.name
$ git config --global user.email

# 取消设置的全局账户
$ git config --global --unset user.name
$ git config --global --unset user.email

# 通过以下语句设置的不同文件夹下的账户信息
$ git config user.name "your name"
$ git config user.email "your email"

重新生成新的 ssh_key

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_pjhubs -C "[email protected]"

在 github or gitlab 上添加生产密钥

$ cd ~/.ssh
# cat 出来的内容全部复制
$ cat id_rsa_pjhubs.pub

本地识别

# 使用-K可以将私钥添加到钥匙串,不用每次开机后还要再次输入这条命令
$ ssh-add -K ~/.ssh/id_rsa_pjhubs        
# 查看已添加的内容
$ ssh-add -l

创建 config 文件,使不同的项目可用不同的信息进行处理

$ cd ~/.ssh/
# 没有config文件时,用以下命令生成
$ touch config

config 文件中键入以下内容:

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_pjhubs

Host git.xxx.com
HostName git.xxx.com
User git
IdentityFile ~/.ssh/id_rsa

# 如果还有继续添加

验证

$ ssh -vT [email protected]
$ ssh -vT [email protected]

# 出现 Hi,your name 等信息就稳妥了