生成PublicKey
建議設置并牢記passphrase密碼短語,以Linux生成為例
Linux:ssh-keygen -t rsa
[私鑰 (id_rsa) 與公鑰 (id_rsa.pub)]
Windows:SecurCRT/Xshell/PuTTY
[SSH-2 RSA 2048]
生成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 forno passphrase): //輸入密碼短語(留空則直接回車)
Enter same passphrase again: //重復密碼短語
Your identification has been saved in/root/.ssh/id_rsa.
Yourpublic key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
aa:8b:61:13:38:ad:b5:49:ca:51:45:b9:77:e1:97:e1 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| .o. |
| .. . . |
| . . . o o |
| o. . . o E |
|o.= . S . |
|.*.+ . |
|o.* . |
| . + . |
| . o. |
+-----------------+
在 /root/.ssh/... 下創(chuàng)建 <strong> authorized_keys </strong> 文件,然后執(zhí)行:
cat id_rsa.pub >> authorized_keys
修改SSH配置文件
編輯sshd_config文件
vim /etc/ssh/sshd_config
禁用密碼驗證
PasswordAuthentication no
啟用密鑰驗證
RSAAuthentication yes
PubkeyAuthentication yes
指定公鑰數(shù)據(jù)庫文件
AuthorsizedKeysFile.ssh/authorized_keys
重啟SSH服務前建議多保留一個會話以防不測
RHEL/CentOS系統(tǒng)
service sshd restart
Ubuntu系統(tǒng)
service ssh restart
debian系統(tǒng)
/etc/init.d/ssh restart
手動增加管理用戶
可以在== 后加入用戶注釋標識方便管理
echo 'ssh-rsa XXXX'>>/root/.ssh/authorized_keys
復查
cat /root/.ssh/authorized_keys