ssh key 多用户配置

在多用户情况下,尽量不要设置全局用户信息

# 添加全局用户信息
git config --global user.name "用户名"
git config --global user.email "邮箱"
#删除全局用户信息
git config --global --unset user.name
git config --global --unset user.email

生成github的ssh_key

$ ssh-keygen -t rsa -C "github@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_github.
Your public key has been saved in id_rsa_github.pub.
The key fingerprint is:
SHA256:K8ZzHA4rrhgHlv7qyP+dAmvpQIq+jPUpbMdjXZncAnE github@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|      . E        |
|       o         |
|  .   .          |
|.+    .oS+       |
|*. . . =*o.      |
|++o.=.*.=.       |
|*=**==o+.        |
|=OBO=o.o         |
+----[SHA256]-----+

生成多个key

生成gitlab的key

$ ssh-keygen -t rsa -C "gitlab@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_gitlab
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_gitlab.
Your public key has been saved in id_rsa_gitlab.pub.
The key fingerprint is:
SHA256:2q7mo4MTScmOvsjl9Gk++rUwqNXvUpW7OeQdGdC95Mo gitlab@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|          . .    |
|         . . o   |
| . .      o o .  |
|  +      o . o   |
| + .    S o +    |
|. + o  + o E     |
|.  B +o.+ + .    |
|o.O o+O..= .     |
|.+.+*X**. .      |
+----[SHA256]-----+

把key添加到相应的网站

配置 config

#该文件用于配置私钥对应的服务器
Host github.com
 User github
 Hostname github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/id_rsa_github
Host 192.168.12.5
 User gitlab
 Hostname 192.168.12.5
 Port 122 # 如果不是22则添加次行
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/id_rsa_gitlab

将密码加入密匙管理器

$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_github
Enter passphrase for /c/Users/Administrator/.ssh/id_rsa_github:
Identity added: /c/Users/Administrator/.ssh/id_rsa_github (/c/Users/Administrator/.ssh/id_rsa_github)
 
$ ssh-add ~/.ssh/id_rsa_gitlab
Enter passphrase for /c/Users/Administrator/.ssh/id_rsa_gitlab:
Identity added: /c/Users/Administrator/.ssh/id_rsa_gitlab (/c/Users/Administrator/.ssh/id_rsa_gitlab)

ssh 互信也可使用次操作

posted @ 2020-09-13 14:49  khlbat  阅读(292)  评论(0)    收藏  举报