如何設定無密碼的 SSH 訪問許可權
在本文中,我們將允許你為 Linux 系統配置免密碼登入,從而使用 SSH 金鑰連線到遠端 Linux 伺服器,而無需輸入密碼,這還將增加兩臺 Linux 伺服器之間的信任,從而便於檔案傳輸。
SSH 是一個開源且受信任的網路協議,用於登入到遠端伺服器以執行命令和程式。這也用於透過安全複製 (SCP) 在網路中從一臺計算機傳輸檔案到另一臺計算機。
建立 SSH 金鑰
# 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: 71:de:c6:b4:c4:8b:31:70:5f:bd:96:60:56:8e:74:b9 root@centos The key's randomart image is: +--[ RSA 2048]----+ | . . .o+. | | o o.=+.. | | . + B...+| | + O o E | | S o * . | | . | | | | | | | +-----------------+
為了安全起見,該金鑰本身會使用強密碼保護,如果密碼用於保護金鑰,則 SSH 代理可用於快取密碼。
將 SSH 金鑰複製到遠端主機
ssh-copy-id root@192.168.1.84 root@192.168.1.84's password: Now try logging into the machine, with "ssh 'root@192.168.1.84'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
驗證無密碼登入
ssh root@192.168.1.84 Last login: Thu Apr 14 17:30:19 2016 from 192.168.2.225 #
從現在起,我們可以在不使用任何密碼的情況下登入到遠端伺服器
在配置上述 3 個步驟後,我們將能夠在不輸入密碼的情況下登入到遠端伺服器,這是最安全的問題之一,某人可能會看到密碼併入侵伺服器,這些型別的身份驗證將幫助我們編寫要在遠端伺服器上執行和計劃的自動備份。
廣告