下載
使用微軟開源的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、使用用戶名密碼進行連接

配置密鑰免登錄
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、免密登錄
免密登錄