一. OpenSSH秘钥的4种格式
秘钥分公钥和私钥各有两个格式分别是:
1)标准私钥使用默认命名为id_rsa,格式如下:
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAgcrGZrk9Jw1UeevJ9/LitE7Ovl/zJcObPlV4l52bPFLTvRBn
mirrTyVX8xMzS7TXID4WeK2/lGQtZXJ7Z8/Op6MHNrpHZZUkaCpJX1GMhkEcA20Z
kzMjCZnRPBt1BEAsKRIHjq7/ZxvSzd/Ip7hsLtrlO+28CCl0LWfw6NQympjdO34H
fHt43Y7DtUU7ABHy9udKoyE6m85vQjLJba5bt2ym2uDsa+FZZ5sXTROSU0m6qV8+
JoGSeQ3tq/MoeGO23bcYbG3trCgy8TXLB4ySUlrZHFrrhQUGA7nzZ8J4pkmo16sF
4rGz3/FjoF2PbU/kyIMNR7oytueO3YiW1al8gwIBJQKCAQBJqnCbKt2E3g1Z9Idj
NtOycer2bc8xG/4qTC+v/4Gexznn2ODa9cPS+YTxvsoWNjToyUsGORm1FkNHan1k
bwaWfx/FHZ4k5fIRm3XAemSDjLzfWZjk19WdqlQpCKoy2FBqVldQ+4oKFrXqeBfw
fW3VZ3sv2fUZY6LNqbI+9PogY8L7/ctQO4C2/0Y/oVMLZtyxeFcGwwFaVZY7H/Fg
zGWlHtn+0N6JXePsahwaFwcLcDJtIjs3ab0jkiHn9fNqEhIY7W+rk3QC0+kDVtvS
IWVp6qGZQrFiSaWCSrU9mOcOSS8yU9u6Lis76FpsvypSfKB6WDXHYtJBa5nnAHBS
7I+1AoGBAO27oxm0MrtA6O0ncxolrjG8eUBbaeC9w0hcmI7Kl3w5gA7yxMlg11g3
rpKrkFn3rn9K9u6gv+gy1VnUCtZC/6J4XXJ7gwkkN9kbjYrEJznz93oPYZlR/kfm
ROgF9wmJalbjsnu0Gg42xoQVucusr9gyJg1ftouBjQ/vP0ZmTwU9AoGBAIvD3tC0
07ZB1+DgwhShurZK4yfOFqCgaCplDJ2K01D5eUiU3OQZAw4VerSkT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g4MIUobq2SuMnzhagoGgqZQyditNQ+XlI
lNzkGQMOFXq0pE51FrD650RhF+77gXQO9hJoYx+rXgBzeXlhRgEUnwMGGk8TZtIp
8sDEVRdFK7R2uFBR61IvjxulhQlZfJF9LI/m5iX+B/JYAp6uqbVLMrZBY1gkvwAA
AIEAmOY+ABE2VAeLKJ4RouCKjLONeSJNKCCtK1rvXk4J9JIqaI6PBtb49AZbNX3X
YcXmXx3X3LFiZRupV6qxAZqjDYoXlHw96yphm7q4mp9HGfN5zdKQjJhmGJUs+E5N
7Y2oeNhnkthtnrZV9SDrNZkaxrjQ7NF0Iu8fYAi6z51Jbh0=
Private-MAC: 38e0a0255e5625f17a32878f03bbaad819f3bb99
4) OpenSSH默认公钥格式*.pub。 格式如下:
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "wzhxyx@gmail.com"
AAAAB3NzaC1yc2EAAAABJQAAAQEAgcrGZrk9Jw1UeevJ9/LitE7Ovl/zJcObPlV4
l52bPFLTvRBnmirrTyVX8xMzS7TXID4WeK2/lGQtZXJ7Z8/Op6MHNrpHZZUkaCpJ
X1GMhkEcA20ZkzMjCZnRPBt1BEAsKRIHjq7/ZxvSzd/Ip7hsLtrlO+28CCl0LWfw
6NQympjdO34HfHt43Y7DtUU7ABHy9udKoyE6m85vQjLJba5bt2ym2uDsa+FZZ5sX
TROSU0m6qV8+JoGSeQ3tq/NoeGO23bcYbG3trCgy8TXLB4ySUlrZHFrrhQUGA7nz
Z8J4pkmo16sF4rGz3/FjoF2PbU/kyIMNR7oytueO3YiW1al8gw==
---- END SSH2 PUBLIC KEY ----
二. git多秘钥配置
以上只有id_rsa.pub格式才能用于设置git仓库。在设置完代码仓库以后,本地还需要配置对应的私钥,Windows可以用代理工具Pagent添加*.ppk拉取代码,也可以通过配置SSH的config文件,实现git多秘钥配置。具体配置如下:
Host github
HostName github.com
User Fred
PreferredAuthentications publickey
IdentityFile /C/Users/zhihao/.ssh/id_rsa_gmail
Host 192.168.1.200
HostName 192.168.1.200
User zhihao.wang
PreferredAuthentications publickey
IdentityFile /C/Users/zhihao/.ssh/id_rsa_company
IdentitiesOnly yes