remote access: LAN-only sshd bootstrap for debugging installs on target PCs (key-based, subnet-scoped) + disable
This commit is contained in:
1 parent
73c59f5c5d
commit
cabdaa4cc8
2 files changed
+66
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
@echo off
|
||||||
|
REM Undo enable_ssh.bat: stop and disable sshd, close the debug firewall rule.
|
||||||
|
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Need admin rights. Relaunching elevated...
|
||||||
|
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
echo === Stop and disable sshd ===
|
||||||
|
net stop sshd 2>nul
|
||||||
|
sc config sshd start= disabled >nul
|
||||||
|
sc query sshd | findstr STATE
|
||||||
|
netsh advfirewall firewall delete rule name="docdebug-ssh" >nul
|
||||||
|
echo Firewall rule docdebug-ssh removed.
|
||||||
|
echo.
|
||||||
|
echo === SSH access disabled ===
|
||||||
|
pause
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
@echo off
|
||||||
|
REM Enable LAN-only SSH access on this PC for docchecker remote debugging.
|
||||||
|
REM Safe in a public repo: installs the Windows OpenSSH Server and allows
|
||||||
|
REM inbound TCP 22 ONLY from the local subnet 192.168.0.0/24, key-based only.
|
||||||
|
REM Revert with disable_ssh.bat from the same folder.
|
||||||
|
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Need admin rights. Relaunching elevated...
|
||||||
|
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
echo === 1. Install Windows OpenSSH Server capability ===
|
||||||
|
powershell -NoProfile -Command "$c = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'; if ($c.State -ne 'Installed') { $c | Add-WindowsCapability -Online | Out-Null; Write-Output 'installed' } else { Write-Output 'already installed' }"
|
||||||
|
if %errorlevel% neq 0 goto :err
|
||||||
|
|
||||||
|
echo === 2. Put debug public key for administrators ===
|
||||||
|
if not exist "C:\ProgramData\ssh" mkdir "C:\ProgramData\ssh"
|
||||||
|
echo ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKdrZtRRqRwyQYHHJTepJnUFS159250wMVQxnVnfjC5H docchecker-debug@macbookair>"C:\ProgramData\ssh\administrators_authorized_keys"
|
||||||
|
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "SYSTEM:F" /grant "BUILTIN\Administrators:F" >nul
|
||||||
|
|
||||||
|
echo === 3. Service sshd: automatic + start ===
|
||||||
|
sc config sshd start= auto >nul
|
||||||
|
net start sshd 2>nul
|
||||||
|
sc query sshd | findstr STATE
|
||||||
|
|
||||||
|
echo === 4. Firewall: TCP 22 only from 192.168.0.0/24 ===
|
||||||
|
netsh advfirewall firewall delete rule name="docdebug-ssh" >nul 2>&1
|
||||||
|
netsh advfirewall firewall add rule name="docdebug-ssh" dir=in action=allow protocol=TCP localport=22 remoteip=192.168.0.0/24 profile=any >nul
|
||||||
|
netstat -ano | findstr ":22" | findstr "LISTEN"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo === DONE ===
|
||||||
|
echo.
|
||||||
|
echo OPERATOR LINE - copy or photo this:
|
||||||
|
whoami
|
||||||
|
hostname
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:err
|
||||||
|
echo.
|
||||||
|
echo === FAILED - take a photo of this window ===
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
Reference in new issue
Block a user