git多用户登录

为不同用户生成密钥

ssh-keygen -t rsa -C “[email protected]

其中会提示你填写密钥名称,其余全部按空格

ssh-keygen -t rsa -C "[email protected]"#你的邮箱地址
Generating public/private rsa key pair.
Enter file in which to save the key (/home/shenzhou/.ssh/id_rsa): em_fffrsa#填写密钥文件名
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in em_shenzhoursa.
Your public key has been saved in em_shenzhoursa.pub.
The key fingerprint is:
SHA256:wSnraK4cTFVw4Cszy4iGQ+M04Lg6Jh96O/iJa9aHEDI [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|    ooo          |
|   . o . .       |
|.   o . +        |
|E. . . o .       |
|oB* . . S        |
|*Bo= o           |
|*+O + .          |
|*OoO .           |
|X*B+o            |
+----[SHA256]-----+

同样,对另一个用户也操作生成密钥,最终,该目录下生成的密钥文件如下:

-rw-------  1 lange  staff  1679 12 18 21:13 em_fff_2_rsa#第二个
-rw-r--r--  1 lange  staff   407 12 18 21:13 em_fff_2_rsa.pub
-rw-------  1 lange  staff  1766  1  4 21:55 em_fffrsa#第一个
-rw-r--r--  1 lange  staff   404  1  4 21:55 em_fffrsa.pub

ssh配置多账户

在生成密钥的.ssh目录下,新建一个config文件,配置多账户规范,举个样例:

Host git.em-data.com  #随便写的
   User [email protected]#第一个公司邮箱账户
   Hostname github.com#随便写的,不清楚有什么用
   IdentityFile ~/.ssh/em_fffrsa#你的密钥路径
   Port   22
Host github.shenzhou.com #随便写的
   User [email protected] #第二个自己github的邮箱账户
   Hostname github.com #随便写的,不清楚有什么用
   IdentityFile ~/.ssh/em_fff_2_rsa

最后验证一下

#ssh -T [email protected]
Welcome to GitLab, zhou!
#ssh -T [email protected]
Hi Fancy265!

好啦~~~

你可能感兴趣的:(git多用户登录)