LINUX ssh-rsa生成公私鑰 實現(xiàn)免密登錄

將公司的所有服務(wù)器設(shè)置為密鑰登錄

1:首先生成所有服務(wù)器的公私鑰

#mac 目錄 /Users/用戶名/.ssh  
#Linux 目錄 /root/.ssh/
#進入 .ssh 文件 
cd /Users/用戶名/.ssh
#執(zhí)行生成密鑰命令
ssh-keygen -t rsa -C "服務(wù)器IP@163.com"
Generating public/private rsa key pair.
#服務(wù)器IP_id_rsa 是輸入的 密鑰名稱例如:47.105.216.12_id_rsa
Enter file in which to save the key (/Users/xxx/.ssh/id_rsa): 服務(wù)器IP_id_rsa
# 直接enter
Enter passphrase (empty for no passphrase):  
# 直接enter
Enter same passphrase again:
#密鑰生成結(jié)束

2:COPY 公鑰到對于服務(wù)器

#執(zhí)行命令
ssh-copy-id -i /Users/xxx/.ssh/服務(wù)器IP_id_rsa.pub root@服務(wù)器IP 
#輸入密碼
root@xxxxxx's password:

3:登錄服務(wù)器設(shè)置開啟密鑰登錄

vim /etc/ssh/sshd_config
#找到 RSAAuthentication  PubkeyAuthentication  沒有就直接加上
RSAAuthentication yes
PubkeyAuthentication yes
#重啟sshd服務(wù)  centos7
systemctl restart sshd.service

4:使用私鑰登錄服務(wù)器

#執(zhí)行命令
#-i 指定私鑰位置  
#不指定會到默認用戶下的.ssh文件找id_rsa.pub文件進行登錄,如果不對會跳出輸入密碼
ssh -i /Users/xxx/.ssh/服務(wù)器IP_id_rsa root@服務(wù)器IP
#登錄成功

5:禁用密碼登錄

vim /etc/ssh/sshd_config
#找到 
PasswordAuthentication no
#重啟sshd服務(wù)  centos7
systemctl restart sshd.service
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容