侧边栏壁纸
  • 累计撰写 90 篇文章
  • 累计创建 489 个标签
  • 累计收到 70 条评论

目 录CONTENT

文章目录

macOS拿到了私钥,怎样制作一个公钥?

火星人
2023-04-12 / 0 评论 / 0 点赞 / 714 阅读 / 0 字 / 正在检测是否收录...
  1. 通常使用ssh登录服务器,使用账号密码不够安全。
  2. 那么就需要用到rsa秘钥。
  3. 通常我们可以拿到一个私钥,比如xxxx.priv。
  4. 一般来说,我们拿到这个文件的时候,内容可能是这样的:
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAngi5ORrKjtYARmU4IccF2Xm8BLgU8oWm8TSMczbgr/mBFK1j
U779CwkAbSvIx8g5zHCjRbvFaUkFohptsMj8Y6mI9Cqjap4iP0IPxPVdDXUlHBAe
kfMAB8lhsjbid/4jYrzHGPj+T1V3Pc7rt8xqtFCbN0jTS5BVY/nbFg2bcFO7uC0X
ohiPPHEZ2gVzNnDMJdlzADUF5V5BGsNe8WRSb9YKHX9nTKbFtx56zrNIwI9CjLd3
Vb9e3wa3eELOubZ9D+cNBcERx0f2LXC/WPat+xp+/8eWDbKjOZQA4zgOQqz8aV7A
+jYojNC9763yxOaOvdNPLUQFnYIPHEfOyRGEvQIDAQABAoIBAQCWWVpOl8yKI9LT
Jk1G5WANTSGxo6haKwluhT3yBw2wncFOeL7818FKFGBRfMxiNX23oJnVKBViW1R+
qoIdJLnp30sqcL5UGuoeIK18BqtmuEJ79mH/HJ60ycSmlkzTN/dWYp9QhOL9eyQc
q5XaoSILNnzVFfXf+AslOHpU+tEdBSQFAgMNGZA9FbbvlTnHPeL6YGCgCOXSA36P
KwqKbJ+QJVv6eSsV4wHiF1mXqZmDjfLJ0xIRNv2kiXJd6YWOtxAXWXV1JTU4T1g9
w5McS1Y3R9dcPMJluDSuxTH0DEg/8uIhCI9zm7l3Ct8rKerGhJ1M6yachScceg7n
AK2GhcwBAoGBAPxOZlYYWO9xJ7Ih4tHG4np9VDpxHYD4k4NGLWBaWeGqt96jSE2v
gzgAPulazS1sEQnvNe3eG58d8IC8ATGcOjbEvqTjiiukrg4xfYXOJ/zfcqoHLG8g
u010Y52q7Ea1FobJ+O/5Z4kx0HfOVqjmZwYlIJGJO02dPhD6NxHdm12BAoGBAKBZ
Agk8928Fp99f/XmqH4rJOvM76MMqfUUZYp+MxXhtqMykHWhNYuqCpmZJr49MnK1N
981tH9MNvy6y4QWGrMUF71tSJtPASc6R8mADNr2DbT0esQRo7XibyTzCZkkiBJYb
xxLq96TODc5UWP8wqKiXWYGOmjtS/map6+5RBL09AoGBALTYgTPO6dhe1CQzc8AH
fYhs0vW85HfwNNPQdm/s8yX01yyG/yln13dJfc6H3i9jmWb0hkREgqnvrNapa3Wi
1HszVK8dxYj41iWoRZ+mIDV5+Fd1It1Yqcif11NJE2ivHkFo/b0MmLDW+uUVCjqw
Q0I9VHXc1pwQTE+g+d4daOKBAoGAfD88AqiJGjAJul6I7KNUOZhf42XCoKfl1Yss
DnFn+j8OkzN/zfhY81o1UgE61hEJPoixwS4TgNigEbFuB3gpm6lTpTFtAJt5FWWl
p5wV6JdUKA4GIGKlz9T3A+umkniXkTEI+rGzHrLDo+Nb6rFrnudX5bn37IwMsMRu
GoYQ5AkCgYEAqW0VHEYhfI9oR2Z77m+EtzPKz+fMGA9rFYQ3fMoY9z1R2waczkB+
CREPSi7aBpIxwgNP3upmNRolkUXduyrRf3eabp01PDkzD0fh39f61nq3xF6JRK7X
DyT564t8ng11YxL7VAnOAbGPzzahDg4oBDRrxr9CaECxZ3pDjBoanKQ=
-----END RSA PRIVATE KEY-----
  1. 注意以上秘钥的格式,RSA PRIVATE KEY,macos是不能直接使用的。
  2. 可以使用命令进行转换:ssh-keygen -p -f xxxxx.priv 这样得到的新的文件内容就修改了:
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAArAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEAnXtjONcgbXum1H0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gGvqDqsnrIRvPHXTsmz+kK
LBTplkksm4cQERfPALm4RpjQ0MX2bTXlozCIo8D99V2FVLlI4nbs8o+Hr+czVnCNkQQHrP
kJFZkrX/35gbF1FFIsoNd42ePMUNidYx7HVPvZtQDk65W/L11l0MbHnd5ac0/amI1spnJi
jWQaEC4oYmAAAAgQDE9mlOgZgNwHMw9V7xZXKBZjAGPtMo52JP5XY6fMVpWEgcjUHCnZxC
jgdj7w0t9F/bf+Rm9pCobTHiDPXFwWTQ2AE384kNSqFkTyF5TkNe1aZXJ/t/HNFYRCPino
d0s+kHkNA8BVE6dHSV8EApkR/htbGaSNOkIvxHSvEH/AhCBwAAAIEAzK+AfjBsYMJZ10vf
nYulHr4fcDn/z7/8L2/3WBbBmBhV3BcgwowUq85KMc34rM/oYkynr2Zt96qPWA/5Ibu55y
F3mCSua83tbB16Y3M4vku/NFhQVN6zL9Wjd1JpcoNYeSd/lU5R2bOXZFKiCP1QphR3/H8t
C1ZCcqbJIdtILHcAAAAAAQID
-----END OPENSSH PRIVATE KEY-----
  1. 再使用命令生成一个pub就好了。
  2. ssh-keygen -e -f xxxx.priv > xxxx.priv.pub
  3. 这样就得到了一个新的文件,内容是公钥。注意,mac上要使用公钥的话,需要吧公钥和私钥放到同一个目录下,并且名称相同,后缀不同。
0

评论区