創(chuàng)建SSH密鑰對(duì)
2019-01-03 23:54:37
16840
使用限制
SSH密鑰對(duì)僅支持Linux系統(tǒng)創(chuàng)建。
創(chuàng)建SSH密鑰操作步驟
使用VNC或服務(wù)器賬號(hào)密碼連接Linux實(shí)例。
打開(kāi)終端,輸入以下指令,查看是否已經(jīng)生成SSH秘鑰。
如果有文件id_rsa.pub 或 id_dsa.pub 說(shuō)明已經(jīng)創(chuàng)建過(guò)SSH密鑰,導(dǎo)入即可。
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
生成新的SSH密鑰。
在服務(wù)器上制作密鑰對(duì)。首先用密碼登錄到你打算使用密鑰登錄的賬戶,然后執(zhí)行以下命令:
[root@host ~]$ ssh-keygen <== 建立密鑰對(duì)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 輸入密鑰鎖碼,或直接按 Enter 留空
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: xxxxxxx
創(chuàng)建完成,安裝公鑰。
輸入以下命令,在服務(wù)器上安裝公鑰:
如此便完成了公鑰的安裝。為了確保連接成功,請(qǐng)保證以下文件權(quán)限正確:
[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh
[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys
設(shè)置SSH,打開(kāi)密鑰登錄。
編輯 /etc/ssh/sshd_config 文件,進(jìn)行如下設(shè)置:
另外,請(qǐng)留意 root 用戶能否通過(guò) SSH 登錄:
當(dāng)你完成全部設(shè)置,并以密鑰方式登錄成功后,再禁用密碼登錄:
最后,重啟 SSH 服務(wù):
[root@host .ssh]$ service sshd restart
PasswordAuthentication no
PermitRootLogin yes
RSAAuthentication yes
PubkeyAuthentication yes
會(huì)員登錄
賬號(hào)登錄還沒(méi)有賬號(hào)?立即注冊(cè)