天天看點

Windows ssh免密登陸Linux配置過程ssh免密登陸Linux

ssh免密登陸Linux

1、生成公鑰和私鑰

公鑰私鑰理論上可以在伺服器生成,也可以在Client端生成,以下為在Windows端生成,Windows系統為Client端。伺服器端采用Centos8。

ssh-keygen -t rsa

不指定檔案名,生成兩個檔案,id_rsa和id_rsa.pub

id_rsa為私鑰

id_rsa.pub為公鑰

2、上傳公鑰

将id_rsa.pub上傳到Linux伺服器

通過指令:cat id_rsa.pub >> authorized_keys,加載到authorized_keys檔案中。

authorized_keys檔案預設在/root/.ssh目錄下。

編輯/etc/ssh/sshd_config檔案

PermitRootLogin yes

PermitEmptyPasswords yes

PasswordAuthentication yes

儲存後,重新開機ssh服務

systemctl restart sshd.service

3、用戶端ssh指令行連接配接伺服器

ssh -i id_rsa [email protected]

4、通過SecureCRT連接配接Linux

點Option->Session Options

在Connetion下SSH2配置項下

Authentication下,勾選PublicKey,點右邊的Properties;

在彈出的Public Key Properties中,根據需要選擇目前會話或全局會話(作用域不同)如隻用于連接配接特定伺服器;

選擇Use session public key setting

Session settings選Use identity or certificate file,輸入id_rsa路徑,或通過檔案選擇框選中剛剛生成的私鑰。

點OK退出Public Key Properties。

完善Session Options其它設定,如Hostname(填伺服器IP)、Port(ssh預設22)、Firewall(None)、Username(Linux伺服器使用者名,本例為root)。點OK儲存。

至此可免密通過SecureCRT連接配接Linux。

5、小插曲

在centos8上,通過指令ssh-keygen -t rsa生成的私鑰,在SecureCRT提示無法找到對應的公鑰(public key)。經過一番折騰,發現Centos8不加-b(私鑰位數,有文檔說64的倍數,有說1024的位數),預設生成的是3072位的密鑰,而本機的SecureCRT隻支援512到2048位的密鑰。

在Centos8下用ssh-keygen -b 2048 -t rsa -f test_rsa,生成的私鑰在SecureCRT上導入成功。

ssh-keygen參考:https://www.cnblogs.com/zhengah/p/4959725.html

sshd參考:https://blog.csdn.net/hddddk/article/details/83142399

繼續閱讀