linux免登陸最常見的方式就是使用基於ssh協議的公鑰認證方式。其原理就是將你機器的公鑰分發到需要免登陸的機器上。
Step1:安裝ssh服務:sudo apt-get install ssh 並開啓服務 service ssh start
Step2 :使用ssh生成公鑰證書
在$home/.ssh目錄下生成公鑰:ssh-keygen -t dsa
ssh-keygen -t dsa
- Generating public/private dsa key pair.
- Enter file in which to save the key (/Users/songjing/.ssh/id_dsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /Users/songjing/.ssh/id_dsa.
- Your public key has been saved in /Users/songjing/.ssh/id_dsa.pub.
- The key fingerprint is:
- 3d:65:12:77:dc:c1:ba:c8:be:70:0e:66:21:71:8c:03 [email protected]<span style="color:#3366ff;">
- </span>
Step3:將公鑰copy到主機和需要登陸的機器的authorized_keys文件中(如麼有,創建即可)
在A主機,scp ~/.ssh/id_dsa.pub [email protected]:~/.ssh/id_dsa.pub
此過程中需要輸入B主機的userB的密碼。
然後,在A,B主機:cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys (將id_dsa.pub的內容追加到 authorized_keys中)
Step4,接下來就可以通過A機器無需密碼就能登陸到B機器上並且執行scp等命令