首先在服務器上生成密鑰
windows
[root@localhost support-files]# ssh-keygen -b 1024 -t rsa 生成密鑰服務器
Generating public/private rsa key pair.dom
Enter file in which to save the key (/root/.ssh/id_rsa): 安裝路徑 直接回車默認就好ssh
Created directory '/root/.ssh'.ide
Enter passphrase (empty for no passphrase): 輸入密鑰的通行短語 spa
Enter same passphrase again: 確認短語3d
Your identification has been saved in /root/.ssh/id_rsa.blog
Your public key has been saved in /root/.ssh/id_rsa.pub.get
The key fingerprint is:generator
b7:d1:01:3d:44:bc:9e:29:48:5b:e6:fd:b3:e0:bc:68 root@localhost.localdomain
[root@localhost support-files]# cd /root/.ssh/ 會生成2個 密鑰
id_rsa id_rsa.pub
[root@localhost support-files]# vi /root/.ssh/authorized_keys 建立authorized_keys文件
[root@localhost support-files]# chmod 700 /root/.ssh/authorized_keys 賦予權限
[root@localhost support-files]# cat /root/.ssh/id_rsa.pub >>/root/.ssh/authorized_keys 將公鑰拷貝到文件裏
若是使用CRT進行遠程連接將id_rsa 拷貝到windows裏
若是使用的是putty 須要轉換 具體步驟以下
使用putty key generator轉換
將id_rsa 放進去 輸入剛纔生成的短語
點擊保存
保存的文件要爲xxx.ppk
[root@localhost ~]# vi /etc/ssh/sshd_config 打開ssh配置文件將如下三行註釋
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes 改成 no 不容許密碼登錄
注:winSCP 用的密鑰文件也是.ppk
最後重啓sshd大功告成