Windows下安裝openssh實現(xiàn)ssh連接

下載

使用微軟開源的openssh

下載地址: https://github.com/PowerShell/openssh-portable

安裝

按照官網(wǎng)的說明安裝openssh即可,官網(wǎng)說明:https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH

1、cd到安裝目錄,執(zhí)行下面的命令

注意:openssh文件夾需要在C:\Program Files下

powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

安裝成功界面

成功安裝

2、開放防火墻端口,可以在winsows控制面板開啟,也可以使用命令開啟,默認端口為22

winsowsServer2012指令:

New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Windows10或者WindowsServer2008

netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22

3、啟動服務(wù)

net start sshd

4、設(shè)置開機自啟動

Set-Service sshd -StartupType Automatic

5、使用用戶名密碼進行連接

![ssh登錄](https://upload-images.jianshu.io/upload_images/1733731-e218002fb8ce8d9f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

配置密鑰免登錄

1、進入c盤下的user目錄,找到當(dāng)前用戶的目錄,一般是administrator

mkdir .ssh

進入到ssh目錄下

# 新建一個txt文件,將服務(wù)器公鑰粘貼進去
notepad authorized_keys
# 重命名
mv authorized_keys.txt authorized_keys

2、修改ssh 服務(wù)的配置文件

打開C:\ProgramData\ssh\sshd_config

注釋掉配置文件中的最后兩行然后保存:

#Match Group administrators
#       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

3、打開服務(wù)

在服務(wù)管理器器中重啟 OpenSSH SSH Server 服務(wù),然后客戶端就可以通過公鑰認證的方式登錄到遠程服務(wù)器了。

4、免密登錄

免密登錄
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。