[精讚] [會員登入]

[CENTOS7 8] ssh登入時免輸入密碼

自動程式需要進到別台機器時,沒辦法使用交談式方式輸入密碼,發現一個簡單的方法設定

分享完整連結 //n.sfs.tw/m10549

分享連結 [CENTOS7 8] ssh登入時免輸入密碼@精讚
(文章歡迎轉載,請尊重版權註明連結來源)
2019-01-19 02:15:48 By 張○○

自動程式需要進到別台機器時,沒辦法使用交談式方式輸入密碼,所以要預先交換好金鑰,這是傳統的作法[1]:

   1. 產生公私金錀
   2. 把公錀加到目標機器中帳號中的目錄下的 ~/.ssh/authorized_keys 中

後來發現 [網管心得]ssh keygen用法@外行中的外行提供一個方法,超級好用的,192.168.1.1是目標ip:

$ ssh-copy-id username@192.168.1.1

/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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@192.168.1.1's password: <==打入該主機的密碼

Number of key(s) added: 1

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

 

錯誤排除

如果出現像這樣的錯誤:

/bin/ssh-copy-id: ERROR: failed to open ID file 'xxx/.pub': No such file or directory

/bin/ssh-copy-id: ERROR: failed to open ID file 'xxx/.ssh/id_rsa.pub': No such file or directory

/usr/bin/ssh-copy-id: ERROR: No identities found

那是因為沒有公私鑰對,請手動建立

# ssh-keygen -t rsa

 

詳細請參考相關連結

參考資料

[1] ssh keygen 免輸入密碼 https://blog.longwin.com.tw/2005/12/ssh_keygen_no_passwd/

相關連結

http://n.sfs.tw/content/index/11033

END
你可能有興趣

[地理] 澳洲柏斯的位置竟然比台灣還要西邊

這近我驚奇的發現,澳洲柏斯的精度竟然比臺灣甚至今晚還要來的西邊

WarSpotting 統計俄國在烏克蘭戰爭中到底是損失了多少軍事裝備或人員

這個網站可以看到俄羅斯在戰場上的軍事人員裝備損失,非常詳細

Mac上 vim的複製貼上不能用

在freebsd系統中發現vim裡的command+c沒辦法選取複製,但command+v可以貼上

check-host 從世界各地檢查你的網站能不能連線?

檢測你的網站能不能暢通?這個網站可讓你知道你的網站是不是「網際網路」還是「區域網路」?

[Smarty4] 出現 modifiers 函式不能用的問題

當我把smarty由3版更新到4.5.1版的時候,出現了Using unregistered function xx in a template這樣的錯誤,該如何解決?

[Docker] docker中要怎麼修改影像的名稱,rename image

透過 build來的image如果沒有指定名稱,事後要怎麼修改影像的名稱?