ssh(密钥管理器-Secure Shell)小结

267 阅读1分钟

如何生成密钥

  • 直接生成: ssh-keygen -o
  • 带关联账号:ssh-keygen -t ed25519(rsa) -C "your_email@example.com"
  • PS:ed25519和rsa时ssh密钥类型,ED25519密钥比 RSA 密钥更安全、更高效。

执行上述命令后会进入如下页面

Enter file in which to save the key (/Users/Jason/.ssh/id_rsa): // ssh密钥存储位置,一般默认就好
Enter passphrase (empty for no passphrase): // 输入密钥口令
Enter same passphrase again: // 确认密钥口令
Your identification has been saved in /Users/Jason/.ssh/id_rsa_igit.
Your public key has been saved in /Users/Jason/.ssh/id_rsa_igit.pub.
The key fingerprint is:
SHA256:++Ik2wTYxuEz5UP/G+XEo7ju8pM8SZhol0ifwdZa15U http://igit.58corp.com
The key's randomart image is:
+---[RSA 2048]----+
|                .|
|               E.|
|      ..o.   . . |
|     =.=+.o ...  |
|    ..O=SO..  =  |
|     .++Oo.o = . |
|     ...+o.o+ .  |
|       *o.*. o   |
|      ..o**o.    |
+----[SHA256]-----+

执行完上面之后,则生成的了ssh密钥

查看密钥

  • cat ~/.ssh/id_rsa.pub 或 cat ~/.ssh/id_ed25519.pub
  • PS:~为"C/Users/Jason"目录,ssh密钥默认存储在这个目录下

将密钥加入到ssh服务中

  1. 第一步:ssh-agent bash
  2. 第二步:ssh-add ~/.ssh/id_rsa

拓展

更多ssh-agent相关,请参考这里

更多ssh-add相关,请参考这里