Skip to content

Instantly share code, notes, and snippets.

@SARDONYX-sard
Created July 29, 2022 09:37
Show Gist options
  • Save SARDONYX-sard/01945825c75377432ba854600b62d471 to your computer and use it in GitHub Desktop.
Save SARDONYX-sard/01945825c75377432ba854600b62d471 to your computer and use it in GitHub Desktop.
How to connect to Windows via ssh using OpenSSH server
# How to automation ssdh?
#
# 1. Execute `compmgmt.msc` on powershell
# 2. Service & application -> duble click service
# 3. Find `OpenSSH SSH Server`
# 4. Select `automation` of `A kind of startup` item
# Are you root?(need `sudo command`. use `winget install gsudo)
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Invoke-Expression "sudo $PsCommandPath $(if ($force) {"-force"})"
Write-Error "Need Administrator"
exit $?
}
Start-Service sshd
@SARDONYX-sard
Copy link
Author

Using VS studio 2022 PowerShell for default shell.

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value 'pwsh.exe -NoExit -Command "&{Import-Module """C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell 86a3a6e9 -SkipAutomaticLocation -DevCmdArguments """-arch=x64 -host_arch=x64"""}"' -PropertyType String -Force

@SARDONYX-sard
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment