生成PublicKey
建議設(shè)置并牢記passphrase密碼短語钥勋,以Linux生成為例
Linux:ssh-keygen -t rsa
[私鑰 (id_rsa) 與公鑰 (id_rsa.pub)]
Windows:SecurCRT/Xshell/PuTTY
[SSH-2 RSA 2048]
生成SSH密鑰對(duì)
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): //建議直接回車使用默認(rèn)路徑
Enter passphrase (empty forno passphrase): //輸入密碼短語(留空則直接回車)
Enter same passphrase again: //重復(fù)密碼短語
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
禁用密碼驗(yàn)證
PasswordAuthentication no
啟用密鑰驗(yàn)證
RSAAuthentication yes
PubkeyAuthentication yes
指定公鑰數(shù)據(jù)庫文件
AuthorsizedKeysFile.ssh/authorized_keys
重啟SSH服務(wù)前建議多保留一個(gè)會(huì)話以防不測(cè)
RHEL/CentOS系統(tǒng)
service sshd restart
Ubuntu系統(tǒng)
service ssh restart
debian系統(tǒng)
/etc/init.d/ssh restart
手動(dòng)增加管理用戶
可以在== 后加入用戶注釋標(biāo)識(shí)方便管理
echo 'ssh-rsa XXXX'>>/root/.ssh/authorized_keys
復(fù)查
cat /root/.ssh/authorized_keys