NatLee / telepy

A Django-based web application for managing and monitoring the reverse SSH tunnels or jump servers.
MIT License
4 stars 1 forks source link

Windows上使用powershell的問題 #9

Closed NatLee closed 3 months ago

NatLee commented 3 months ago

如題

當endpoint是windows機器且SSH的shell是使用powershell endpoint端會無法讀取authorized_keys

導致只能用密碼登入

h-alice commented 3 months ago

About the Issue of Logging in SSH Server for Windows with Public Key

症狀

TL;DR

觀察

Windows上的SSH伺服器會從下列路徑讀取設定檔:

C:\ProgramData\ssh\sshd_config

從設定檔中可以看到一行關於AuthorizedKeys的設定:

Match Group administrators
       AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

由此可見, 對於管理者有另一套公鑰的設定檔 (應該是因為安全理由, 但我不認為真的比較安全😂)

解決方法

如同一般的authorized_keys, 將公鑰放入administrators_authorized_keys, 重新啟動SSHD即可

net stop sshd
net start sshd
h-alice commented 3 months ago

不過這牽涉到編輯administrators_authorized_keyssshd_config 兩個都要提權 你覺得要如何處置

NatLee commented 3 months ago

其實還好,因為設定是在目標機器 所以理論上,目標機器會有全權限

如果沒有admin權限,但可以使用password的話,至少還能被反向登入

NatLee commented 3 months ago

這邊實測後,已完成

並且在建立通道的時候,加入提示

https://github.com/NatLee/telepy/commit/9aa1cfafea3dbb03a06742cafc3542c584ef4c58

image

這個issue可以close了 :D