[openssh]windows 10使用cygwin安裝openssh服務端

install-openssh-with-cygwin-on-windows-10html

原本windows10上已經有內置的openssh,我可能愛折騰不肯意使用內置的,因此使用cygwin從新安裝了一個ssh服務.git

安裝步驟總結

  1. 安裝cygwin
  2. 使用管理員權限運行cygwin安裝opensshopenssl
  3. ssh-host-config命令開始配置ssh
  4. windows10內置的sshdssh-host-config默認的服務名衝突解決
  5. 一系列ssh-host-config配置,包括daemon名稱 ntsec和建立默認的cyg_server來運行sshd服務
  6. ssh-user-config生成用戶的密鑰(非必須,可使用密碼登錄,用戶就是windows的正經常使用戶)
  7. 啓動服務net start cygsshd
  8. 使用putty登錄localhost測試
  9. 卸載ssh
  10. 從新安裝ssh

注意:cygwin使用的是windows的用戶和權限,因此默認/etc/下是沒用passwdgroup等文件的,不要太驚訝。github

開始我也沒用搞明白,並且ssh-host-config中建立一個cyg_server用戶是真實的windows帳戶,可是須要組策略纔可以看到,這個用戶用來啓動sshd服務的,並且不能用來登錄windows,由於是一個令牌用戶,在組策略>計算機配置>windows配置>安全設置>本地策略>用戶權限分配> 建立一個令牌對象中看到。windows

cygwin安裝openssh和openssl

假設你已經安裝了cygwin,使用cygwin安裝openssh和openssl詳情看參考:安全

how-to-get-ssh-command-line-access-to-windows-7-using-cygwin/bash

修復sshd service is already installed.

警告:sshd service is already installed.oracle

sshd-service-installed-error

windows10-build-in-openssh

出現sshd service is already installed.的問題是由於windows 10內置了一個openssh,形成了衝突,如今只須要修改cygwin安裝的openssh中的默認的sshd服務名稱。dom

修改默認的sshd服務名

路徑: C:/cygwin64/bin/sshd-host-config (32位的有所區別,找不到用everything搜索一下啊)ssh

修改: service_name=sshd 爲 service_name=cygsshd (cygsshd自定義的)測試

修改完以後從新執行ssh-host-config,上面的問題解決.

下面是運行中的截圖.

ssh-host-config

sshd-as-service-ntsec

建議使用默認的cyg_server,沒用必要從新自定義,我當時也是好奇,搞得走了不少彎路。

config-user-name-password

啓動服務

也能夠重啓一下系統,服務會自動啓動

net start cygsshd  # cygsshd是自定義的service_name
# 或者使用cygwin運行
cygrunsrv -S cygsshd
複製代碼

ssh-user-config

選擇生成用戶的RSA口令就好了,RSA比較經常使用,其它的不是很經常使用。

卸載ssh服務

# 刪除sshd服務, sshd時默認的服務名,若是你定義了,輸入你的服務名
cygrunsrv --stop sshd
cygrunsrv --remove sshd

# Delete any sshd or related users (such as cyg_server) from /etc/passwd
# (use your favorite editor)

# Delete any sshd or related users (such as cyg_server) from the system
# 這裏刪除的是windows上的用戶
net user sshd /delete
# 若是ssh-host-config配置過程當中沒用使用cyg_server,請替換爲你自定義的名字
net user cyg_server /delete
複製代碼

重裝ssh從新設置權限

若是設置權限不行,刪除sshd.log和empty文件夾.

chown <USERNAME> /var/log/sshd.log
chown -R <USERNAME> /var/empty
chown <USERNAME> /etc/ssh*
chmod 755 /var/empty
chmod 644 /var/log/sshd.log

複製代碼

參考資料

Installing Cygwin and Starting the SSH Daemon

how-to-get-ssh-command-line-access-to-windows-7-using-cygwin/

cygwin-sshd-on-windows-domain

how-to-regenerate-ssh-client-keys

mkpasswd

mkgroup

how-to-uninstall-reinstall-cygwin-to-use-the-sshd

相關文章
相關標籤/搜索