1
+ <powershell >
2
+ # Execute it with elevated permissions
3
+ # Description:
4
+ # This script install automatically the open-ssh feature and enable it
5
+
6
+ # enable tls1.2 for downloads
7
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
8
+
9
+ # creating openssh folder and download the zip
10
+ mkdir c:\openssh-install
11
+ cd c:\openssh-install
12
+
13
+ #update the last version if you want the last release
14
+ Invoke-WebRequest -Uri "https://github.com/PowerShell/Win32-OpenSSH/releases/download/V8.6.0.0p1-Beta/OpenSSH-Win64.zip" -OutFile .\openssh.zip
15
+ Expand-Archive .\openssh.zip -DestinationPath .\openssh\
16
+ cd .\openssh\OpenSSH-Win64\
17
+
18
+ # required for enable the service
19
+ setx PATH "$env:path;c:\openssh-install\openssh\OpenSSH-Win64\" -m
20
+
21
+ # required for install the service
22
+ powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
23
+
24
+ # required for execute remote connections
25
+ New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
26
+
27
+ net start sshd
28
+
29
+ # auto enable for each restart machine
30
+ Set-Service sshd -StartupType Automatic
31
+
32
+ #Set default shell to powershell
33
+ New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
34
+
35
+ # Configure SSH for the specific user "test-user" with public key "12345"
36
+ $sshUser = "test-user"
37
+ $sshPublicKey = "${ var.public_key} "
38
+ $sshUserPath = "C:\ProgramData\ssh\administrators_authorized_keys"
39
+
40
+ # Append the public key to the authorized_keys file for the user
41
+ Add-Content -Path $sshUserPath -Value "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC12345"
42
+
43
+ # Restart the sshd service to apply the changes
44
+ Restart-Service sshd
45
+ </powershell >
46
+ <persist >true</persist >
0 commit comments