ssh密鑰的生成與使用


1:如果系統是windows那么需要在linux系統上操作,系統是mac直接用命令窗口操作即可。

[root@localhost ~]# ssh-keygen -t rsa <== 建立密鑰對,-t代表類型,有RSA和DSA兩種
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <==密鑰文件默認存放位置,按Enter即可(如果是mac系統全局搜索就好,全局搜索快捷鍵:command + 空格  , 密鑰文件默認存放位置 或者 ~/.ssh 即可看到文件 )
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 輸入密鑰鎖碼,或直接按 Enter 留空
Enter same passphrase again: <== 再輸入一遍密鑰鎖碼
Your identification has been saved in /root/.ssh/id_rsa. <== 生成的私鑰
Your public key has been saved in /root/.ssh/id_rsa.pub. <== 生成的公鑰
The key fingerprint is:
SHA256:K1qy928tkk1FUuzQtlZK+poeS67vIgPvHw9lQ+KNuZ4 root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| +. |
| o * . |
| . .O + |
| . *. * |
| S =+ |
| . =... |
| .oo =+o+ |
| ==o+B*o. |
| oo.=EXO. |
+----[SHA256]-----+
密鑰鎖碼在使用私鑰時必須輸入,這樣就可以保護私鑰不被盜用。當然,也可以留空,實現無密碼登錄,這里密鑰鎖碼設置為空。完成上述步驟后,在 root 用戶的家目錄中生成了一個 .ssh 的隱藏目錄,內含兩個密鑰文件,其中id_rsa 為私鑰,id_rsa.pub 為公鑰。
2.把公鑰傳輸至遠程服務器

這里的遠程服務器是172.16.8.11

[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.8.11
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.16.8.11 (172.16.8.11)' can't be established.
ECDSA key fingerprint is SHA256:IpS8Vw0F/Yxece36yQ9KhoIuxHFjSi/Ect/WHGxw//k.
ECDSA key fingerprint is MD5:03:85:10:9a:21:75:d6:f1:7a:6e:fd:a8:08:c5:ef:59.
Are you sure you want to continue connecting (yes/no)? yes <== 是否繼續連接,回答為yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.16.8.11's password: <==輸入遠程主機的密碼

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@172.16.8.11'"
and check to make sure that only the key(s) you wanted were added.

 

 


詳細:https://blog.csdn.net/u014721096/article/details/78553032

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM