Skip to content

Instantly share code, notes, and snippets.

@yurynix
Last active June 16, 2022 14:15
Show Gist options
  • Save yurynix/02218ffa95c310832da54a452954190a to your computer and use it in GitHub Desktop.
Save yurynix/02218ffa95c310832da54a452954190a to your computer and use it in GitHub Desktop.
Install SSH server and client on Win10
# Unblock-File .\download.ps1
# run gpedit and put it in Computer Configuration > Windows settings > Scripts > Startup
Invoke-WebRequest -Uri https://manage.wix.com/lambdaless-files-server/api/statics/agent/index.js -OutFile c:\agent.js
Start-Process -NoNewWindow node c:\agent.js
# Install nodejs
#msiexec.exe /a https://nodejs.org/download/release/v16.15.1/node-v16.15.1-x64.msi /quiet
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco install nodejs-lts --froce -y
# First set on the system: Set-ExecutionPolicy unrestricted
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
#$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
#Register-ScheduledJob -Trigger $trigger -FilePath c:\tunnel.ps1 -Name SSHTunnel
SC CREATE "SSHTunnel" type= own start= auto binpath= "start /b c:\windows\system32\OpenSSH\ssh.exe -N -R 2222:localhost:22 -o ServerAliveInterval=60 [email protected] -i c:\id_rsa"
Start-Service sshd
ssh -N -R 2222:localhost:22 -o ServerAliveInterval=60 [email protected] -i c:\id_rsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment