id_rsa id_rsa.pub

Posted 654321cc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了id_rsa id_rsa.pub相关的知识,希望对你有一定的参考价值。

id_rsa  私钥

id_rsa.pub  公钥

https://blog.csdn.net/qq_36663951/article/details/78749217

https://blog.csdn.net/diyxiaoshitou/article/details/52471097

 

id_rsa.pub 的作用

  上班的第一天,上司大哥都会说:待会给我发个公钥吧。 这里说的公钥其实就是id_rsa.pub。上司大哥是要把我们的客户端公钥上传到服务器,然后再把这个客户端公钥添加到authorized_keys。添加后,服务器就会认为你这个客户端为可信任。你则可以访问这个服务器了。

 

  个人阿里云测试:

[[email protected] ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in y.
Your public key has been saved in y.pub.
The key fingerprint is:
SHA256:fI5TxBpVS199BCl8lmo21bY1MC4hI5mlv3G3QVto+5M [email protected]
The keys randomart image is:
+---[RSA 2048]----+
|       .++.+ooo*+|
|       oooo.=oOo*|
|       .. [email protected]=|
|       ..+  O +. |
|        Soo+ *   |
|         =+ . + .|
|        o..  . E |
|         .      .|
|                 |
+----[SHA256]-----+

 

  在 /root 目录下多了两个文件,y 和 y.pub

[[email protected] ~]# pwd
/root
[[email protected] ~]# ls -al
total 128
dr-xr-x---. 12 root root  4096 Jul  7 20:10 .
dr-xr-xr-x. 18 root root  4096 Jun 15 19:52 ..
-rw-------   1 root root 16146 Jul  5 00:41 .bash_history
-rw-r--r--.  1 root root    18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root   176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root   176 Dec 29  2013 .bashrc
drwx------   5 root root  4096 Jun 20 21:11 .cache
drwxr-xr-x   5 root root  4096 Jul  4 00:10 code
drwx------   7 root root  4096 Jun 20 21:11 .config
-rw-r--r--.  1 root root   100 Dec 29  2013 .cshrc
-rw-------   1 root root    87 Jun 13 20:09 .dbshell
drwx------   3 root root  4096 Jun 20 03:02 .dbus
-rw-r--r--   1 root root   106 Jun 14 12:56 dump.rdb
drwx------   2 root root  4096 Jul  7 03:34 .gnupg
-rw-------   1 root root   314 Jun 20 03:02 .ICEauthority
drwxr-xr-x   3 root root  4096 Jun 20 02:44 .local
-rw-------   1 root root     0 Jun 13 13:38 .mongorc.js
-rw-------   1 root root    73 Jun 14 12:53 .mysql_history
drwxr-xr-x   2 root root  4096 Oct 15  2017 .pip
drwxr-----   3 root root  4096 Jun 13 13:23 .pki
-rw-r--r--   1 root root    64 Oct 15  2017 .pydistutils.cfg
-rw-------   1 root root   784 Jun 20 22:15 .rediscli_history
drwx------   2 root root  4096 Jun  5 00:43 .ssh
drwxr-xr-x   3 root root  4096 Jun 25 22:50 .subversion
-rw-r--r--.  1 root root   129 Dec 29  2013 .tcshrc
-rw-------   1 root root  5443 Jun 19 23:49 .viminfo
-rw-r--r--   1 root root    11 Jun 14 12:13 .vimrc
-rw-------   1 root root     0 Jun 20 03:02 .Xauthority
-rw-------   1 root root  1766 Jul  7 20:10 y
-rw-r--r--   1 root root   410 Jul  7 20:10 y.pub

  查看

[[email protected] ~]# cat y.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGVjc7/p/5l0U4bniHBozg5t7sHMhLFfIGf17GoZaWA5OPflRBMr3YrJ1uvigNrzhEIZGvYnb6W+coUHuV9wu9ht6DvIkcFVSQsv/IEi/GbdkAonTH7/MlehYw7rv6FcXF635Re5hD8fFrci8pMTdv++IR5eDtjVHmhl+QNAUKpnNC+GkPyNSvtxxZxURKs0Qj8hFamKIIAdqWKZlyRBk7J6DghVzugfDKrDnkRCcLQ2YhSH90BBzbqngJP23nhRsLG4NN1MObQY/3bXL0k7EBWT1JfJN/zAyeWEV9ElyqBBkdUDs+2A69LO39WfhAwgIVPgzuLpxPHtDMrbtjGH8f [email protected]
[[email protected] ~]# cat y
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: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MNcbtGRDHSoISC8ExYkPg7SZJVj3pwXrboPed
2AAF26DvThLdMBrCaBbxZgKJ/zUfmK6lMSoJ7sv56/qhRufpHMQeNNhzTISsbTBe
wmTcjiUl8x+txX5bkPRbeAGukqS9OnPbhat91R1hc6b59CBeKwMNsDb4u1ZFnxbf
Z3OcwQzK07jr64o2KlPwhtcG4jvq4cuIrYoZpvRicl6LsyvEkkoVggf2YYEE5Kmf
plLN/TnFstx5MTf7shZvF31LW+pa90bQAXc+kQVxw0g7fUlu58YVQPmSWJEHJXSa
6Vmy/AyX9Gw93ibTot77nAda5qPP63WZZhd+al7Vjz9lUwqP2d5Csfg4cFfW9ev6
Ht+m3SLs5SZsNoAERy4nrtGIlEN3KKAuseVGbwHFkyo7TYsF6eUdDdwiBBLlFztB
lCC7frq2V8x2kvSp7C1s9C7K5ItBS7y7Rh2EyU8e4WPoJzZ28to+KVigrG6xSLyq
wS5Hc2A6XnPybZLM9rCPniGzC7uD4fZNSBXPnaB4jzx8ViNM5HgA/mVOsCTp2sP4
ds+Ayy9P13lKFlCOmFVnh8pgn+GYsU8LVKZ0FiFZbEK6Y9CxOTE969lxKEpOD4fI
-----END RSA PRIVATE KEY-----

 

  查看authorized_keys

[[email protected] .ssh]# cd ~/.ssh/
[[email protected] .ssh]# ls -al
total 8
drwx------   2 root root 4096 Jun  5 00:43 .
dr-xr-x---. 12 root root 4096 Jul  7 20:10 ..
-rw-------   1 root root    0 Jun  5 00:43 authorized_keys
[[email protected] .ssh]# cat authorized_keys 

 

以上是关于id_rsa id_rsa.pub的主要内容,如果未能解决你的问题,请参考以下文章

为啥 id_rsa 和 id_rsa.pub 文件的内容是字母?

如何从 Java 生成 ssh 兼容的 id_rsa(.pub)

在winsshd 中添加id_rsa.pub 实现Windows 服务器主机自动信任Linux 客户端

ssh-keygen -t rsa 创建时 id_rsa.pub 为空

id_rsa.pub 文件 SSH 错误:格式无效

id_rsa.pub不是公钥文件