使用密鑰文件登錄
首先將密鑰應用到主機,然后下載密鑰,將密鑰拷貝到要訪問主機的電腦上,最后通過此文件不需要密碼可直接訪問到主機

[deployer@Bigcolud ~]$ ssh -i ~/dyd/csb-dyd.pem root@10.166.66.66
The authenticity of host '10.166.66.66 (10.166.66.66)' can't be established.
ECDSA key fingerprint is SHA256:P2ydg2DT+NDMdYv8C8S8RpWE62znCn0OWiQJkqI6TBh.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.166.66.66' (ECDSA) to the list of known hosts.
You have logged onto a secured server..All accesses logged
Authorized users only. All activity may be monitored and reported
.----..-. .-..----.
| {} \\ \/ / | {} \
| / } { | /
`----' `--' `----'
Welcome to BigCloud Enterprise Linux 8 (GNU/Linux 4.19.0-193.1.3.el8.bclinux.x86_64 x86_64)
System information as of Thu Jun 11 20:36:37 CST 2021
* System CPU load: 0.30 0.24 0.10 * System uptime: 20:36:37 up 2 min
* Active sessions: 1 * Memory usage: 547 / 838 MB
* Processes count: 101
* Get Support :
* Ask Questions:
http://forum.bclinux.org
* Contact US :
MAIL : support@bclinux.org / TEL : 400-1234567-8
[root@csb-dyd611 ~]#
若出現以下警告並讓輸入密碼登錄,說明使用密鑰文件登錄失敗
[deployer@Bigcolud ~]$ ssh -i ~/dyd/csb-dyd.pem root@10.166.66.66
The authenticity of host '10.166.66.66 (10.166.66.66)' can't be established.
ECDSA key fingerprint is SHA256:P2ydg2DT+NDMdYv8C8S8RpWE62znCn0OWiQJkqI6SBg.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.166.66.66' (ECDSA) to the list of known hosts.
You have logged onto a secured server..All accesses logged
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/deployer/dyd/csb-dyd.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/deployer/dyd/csb-dyd.pem": bad permissions
root@10.166.66.66's password:
出現此情況是由於文件權限問題造成的,修改文件權限即可
chmod 600 ~/dyd/csb-dyd.pem # 將權限修改為600
ssh -i ~/dyd/csb-dyd.pem root@10.166.66.66 # 再次使用密鑰即可登錄成功
免密登錄
在兩台主機上都生成密鑰對,執行以下命令
ssh-keygen -t rsa
將一台主機做為客戶端,將公鑰導入到認證文件中
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
將認證文件authorized_keys
上傳到另一台主機(即服務端)的.ssh
目錄下

此處的.ssh
目錄若非通過命令ssh-keygen -t rsa
創建,而是通過命令mkdir .ssh
創建,則需要更改權限
chmod 700 .ssh/
chmod 600 .ssh/authorized_keys
最后,在客戶端即可直接登錄到服務器,或者通過私鑰id_rsa
訪問服務端
ssh root@192.166.66.22
ssh -i .ssh/id_rsa root@192.166.66.22
