48 lines
1.9 KiB
Batchfile
48 lines
1.9 KiB
Batchfile
@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
|