Linux 免密登入
阿新 • • 發佈:2020-09-17
# 使用ssh-keygen生成SSH鑰匙,可新增引數設定密碼,金鑰型別等 # 會詢問是否自定義檔案,設定密碼等,一路回車即可。 root@DESKTOP-FVOICCT:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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: SHA256:***@***
執行完成,會在使用者家目錄的.ssh目錄,生成【id_rsa】【id_rsa.pub】兩個檔案.
- authorized_keys:存放遠端免密登入的公鑰,主要通過這個檔案記錄多臺機器的公鑰(初始不存在該檔案) *
- id_rsa : 生成的私鑰檔案 *
- id_rsa.pub : 生成的公鑰檔案*
- know_hosts : 已知的主機公鑰清單*
將公鑰上傳到指定伺服器的使用者家目錄下:
# 需要輸入指定伺服器,指定使用者的密碼
ssh-copy-id -p 22 [email protected]
完成後,會在本機.ssh目錄下生成一個know_hosts.
會在指定伺服器,指定使用者家目錄.ssh目錄下,生成一個authorized_keys檔案,裡面是我們服務的公鑰。
測試:
ssh -p 22 root@ip
配置遠端計算機別名,是我們訪問更加方便。
vi ~/.ssh/config
Host ningchuan
HostName 127.0.0.1
User root
Port 22
就可以方便的使用ssh host免密登入了