在兩台服務器之間建立信任關系解決scp,ssh等不用輸入密碼等問題


 
1、在Client上root用戶執行ssh-keygen命令,生成建立安全信任關系的證書。 
Client端
# ssh-keygen  -t rsa
   Generating public/private rsa key pair.
   Enter file in which to save the key (/root/.ssh/id_rsa): 
   Enter passphrase (empty for no passphrase):            <-- 直接輸入回車
   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:
   49:9c:8a:8f:bc:19:5e:8c:c0:10:d3:15:60:a3:32:1c root@Server
注意:在程序提示輸入passphrase時直接輸入回車,表示無證書密碼。
上述命令將生成私鑰證書id_rsa和公鑰證書id_rsa.pub,存放在用戶家目錄的.ssh子目錄中。
 
2. 將服務器Client的公鑰證書id_rsa.pub復制到機器Server的root家目錄的.ssh子目錄中
 
Client端
# scp -p /root/.ssh/id_rsa.pub root@121.40.125.251:/root/.ssh/
   root@192.168.0.20's password:          <-- 輸入機器Client的root用戶密碼
   id_rsa.pub           100% |**************************|   218       00:00
Server端
# mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys   
或者 cat id_rsa.pub >authorized_keys
經過以上2步,就在機器Client的root和機器Server的root之間建立安全信任關系。下面我們看看效果:
Client端
 
# scp -i  /root/ .ssh/id_rsa text  root@192.168.0.20:/root
   text                 100% |**************************|    19       00:00
若ssh端口非22端口,請使用-P參數后跟端口號
 
Ok!

 


免責聲明!

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



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