SSH密鑰設置
建立密鑰對使用如下命令
ssh-keygen
執(zhí)行ssh-keygen顯示如下
[root@host ~]$ 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:
0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
有以下幾處需要注意傲绣,可根據(jù)個人情況定是輸入密鑰鎖碼兆龙,或直接按 Enter 留空
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
生成的私鑰和公鑰會保存在/root/.ssh路徑,為id_rsa 私鑰忙迁,id_rsa.pub為公鑰
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
在服務器上安裝公鑰
進入/root/.ssh 執(zhí)行如下命令
cat id_rsa.pub >> authorized_keys
如此便完成了公鑰的安裝翔怎。為了確保連接成功配名,請保證下面文件權限正確
[root@host .ssh]$ chmod 600 authorized_keys
設置ssh秘鑰登錄功能鹉梨,編輯/etc/ssh/sshd_config文件,進行如下設置:
RSAAuthentication yes #RSA認證
PubkeyAuthentication yes #pubkey認證
另外,請留意 root 用戶能否通過 SSH 登錄:
PermitRootLogin yes #允許root登
當你完成全部設置茴她,并以密鑰方式登錄成功后寻拂,再禁用密碼登錄:
PasswordAuthentication no
最后,重啟 SSH 服務:
sudo service ssh restart
sshkey生成參考
本地私鑰連接
在putty上登錄時需要把密鑰格式轉換成putty可用格式丈牢,下載putty密鑰生成工具 puttygen.exe進行如下操作
加載私鑰文件
點擊顯示所有文件祭钉,找到你的私鑰文件
保存轉換后的私鑰文件
輸入要連接的主機IP ,選中SSH的Auth
點擊browse選中你生成的ppk文件
點擊open打開
使用PuTTY密鑰認證機制遠程登錄Linux