windows 安裝ssh server
win10
win10 版本更新後,本身攜帶了openssh client和openssh server
安裝方法:
設置 -> 應用 -> 管理可選功能 -> 添加功能 -> “openssh 客戶端” ”openssh 服務器"
問題記錄:
- 無法安裝成功
通過查看 “查看可選功能歷史記錄” 獲取問題的詳細信息 - 網絡原因
需要將當前網絡置於不收費網絡中,否則安裝失敗
win7 & win8
此處推薦下載安裝openssh powershell版本,簡單方便
-
下載地址
下載最新版本,openssh-win64.zip
-
安裝步驟
-
解壓
將openssh-win64.zip解壓到任意路徑下,記:DESCOMPRESSION_PATH
(decompression path,解壓縮路徑) -
安裝
在cmd
中進入到%DESCOMPRESSION_PATH%
路徑中,輸入#安裝openssh server powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1 #將sshd服務設置爲自啓動 sc config sshd start= auto #啓動sshd服務 net start sshd
-
修改配置文件
win中默認的配置文件在__PRAGRAMDATA__\ssh\ssh_config
文件中,__PRAGRAMDATA__
代指的路徑是C:\ProgramData\
是一個隱藏文件夾端口號:Port 22
密鑰訪問:PubkeyAuthentication yes
密碼訪問:PasswordAuthentication no
空密碼:PermitEmptyPasswords no -
無密碼登錄配置
新版本配置Administrator密鑰配置文件不在.ssh/authorized_keys
中,變成了%programdata%\ssh\administrators_authorized_keys
文件中,
首先進入到%programdata%\ssh\
中,如果沒有文件administrators_authorized_keys
, 首先創建,
再在cmd
中執行icacls administrators_authorized_keys /inheritance:r
icacls administrators_authorized_keys /grant SYSTEM:(F)
icacls administrators_authorized_keys /grant BUILTIN\Administrators:(F)修改ssh_config文件:
AuthorizedKeysFile %programdata%/ssh/administrators_authorized_keys
重啓sshd服務即可
安裝及使用問題記錄
-
初次連接服務器時,需要進行驗證
ssh -o StrictHostKeyChecking=no user@xxx.xxx.xxx.xxx
StrictHostKeyChecking
可以實現不需要輸入yes/no
即可進入連接環節 -
使用ssh key文件,實現免密登錄問題
首先使用ssh-keygen
生成密鑰和公鑰,詳細方案參考:使用ssh實現免密登錄ssh -i identity_file -o StrictHostKeyChecking=no user@xxx.xxx.xxx.xxx
identity_file
即爲密鑰 -
出現
connection reset by xxx.xxx.xxx.xxx port xx
,這時需要重新配置server,刪除__PROGRAMDATA__\ssh
文件夾,重新啓動sshd
服務即可