【Ubuntu 技巧】SSH 免密登陸

為了進一步提升 Ubuntu Server 服務器的安全,SSH 必須使用證書驗證登陸


首先登陸 SSH 登陸服務器

【Ubuntu 技巧】SSH 免密登陸


【Ubuntu 技巧】SSH 免密登陸


改為 root 用戶

sudo su
輸入密碼 

【Ubuntu 技巧】SSH 免密登陸


修改 root 密碼

passwd root
密碼
密碼 

【Ubuntu 技巧】SSH 免密登陸


# 創建 ssh key,加密默認是 2048,這裡改為 4096

ssh-keygen -t rsa -b 4096 -C "login name@ip or domain"
#範例:ssh-keygen -t rsa -b 4096 -C "ianext@192.168.18.139"
#範例:ssh-keygen -t rsa -b 4096 -C "ianext@www.ianext.com"
一路回車就可以了 

【Ubuntu 技巧】SSH 免密登陸


ssh-copy-id 将 key 写到远程机器,并產生文件 id_rsa 等文件

ssh-copy-id ianext@192.168.18.139

【Ubuntu 技巧】SSH 免密登陸


會提示你登陸 SSH,輸入 Login Account Password,當登陸成功之後,就可以退出 exit

exit

【Ubuntu 技巧】SSH 免密登陸


修改文件權限

cat ~/.ssh/id_rsa.pub | ssh ianext@192.168.18.139 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

【Ubuntu 技巧】SSH 免密登陸


使用 SFTP 工具將 .ssh 文件的文件都拷貝到你要登陸 SSH 的機器上

默認【.ssh】文件夾一般都在當前賬號下,由於是隱藏文件所以 ……

【Ubuntu 技巧】SSH 免密登陸


將服務器的密鑰文件都拷貝到自己電腦后,就可以使用 SSH 工具進行免密登陸

我這裡使用的是 Xshell 6,請依據 1,2,3 進行操作。

【Ubuntu 技巧】SSH 免密登陸


測試結果

【Ubuntu 技巧】SSH 免密登陸

正文完
文章赞赏 謝謝支持
post-qrcode
 0
Implementer
版权声明:本站原创文章,由 Implementer 于2020-05-01发表,共计669字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。