先說下環(huán)境聋庵,我用的是阿里云ESC服務(wù)器,裝載CentOS 7.2的系統(tǒng)盤芙粱,沒有選擇任何的附加包之類的祭玉。
? ? ? ? 為了安全性的考慮,我想要配置使用公密鑰的方式去連接服務(wù)器春畔。這里需要修改服務(wù)器的SSH服務(wù)脱货,主要分為三步:修改服務(wù)器SSH配置、客戶端生成公鑰拐迁、服務(wù)器加入客戶端公鑰蹭劈,下面是我操作的過程:
一. 生成密鑰的公鑰和私鑰
# ssh-keygen -t rsa?
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:
? ? ? ? ? ? ? 1c:37:a8:a3:65:a2:4a:89:ab:46:30:ad:54:d1:40:eb root@iZ28vo50eu5Z
二. 設(shè)置sshd? 服務(wù)器服務(wù)
1. 登錄服務(wù)器,輸入命令vi /etc/ssh/sshd_config修改配置文件
2. 找到RSAAuthentication线召、PubkeyAuthentication、AuthorizedKeyFiles多矮、StrictModes所在的行缓淹,如果被#注釋了,就取消#號塔逃,改為如下配置:
?修改以下設(shè)置:?
ChallengeResponseAuthentication no?
PasswordAuthentication no?
UsePAM no?
RSAAuthentication?yes
PubkeyAuthentication?yes
AuthorizedKeyFiles?.ssh/authorized_keys ? ? ??
StrictModes no
修改好ssh的配置文件后保存并退出讯壶,使用systemctl restart sshd.service重啟SSH服務(wù)。然后導(dǎo)入到遠(yuǎn)程工具中