Created
April 26, 2022 18:13
-
-
Save aravindhp/7ddd403761425b67e53797bd84f362dd to your computer and use it in GitHub Desktop.
gcloud-win
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-RandomPassword { | |
Add-Type -AssemblyName 'System.Web' | |
return [System.Web.Security.Membership]::GeneratePassword(16, 2) | |
} | |
$UserAccount = Get-LocalUser -Name "Administrator" | |
$password = ConvertTo-SecureString Get-RandomPassword -asplaintext -force | |
$UserAccount | Set-LocalUser -Password $password | |
$UserAccount | Enable-LocalUser | |
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 | |
$firewallRuleName = "ContainerLogsPort" | |
$containerLogsPort = "10250" | |
New-NetFirewallRule -DisplayName $firewallRuleName -Direction Inbound -Action Allow -Protocol TCP -LocalPort $containerLogsPort -EdgeTraversalPolicy Allow | |
Set-Service -Name sshd -StartupType 'Automatic' | |
Start-Service sshd | |
$pubKeyConf = (Get-Content -path C:\ProgramData\ssh\sshd_config) -replace '#PubkeyAuthentication yes','PubkeyAuthentication yes' | |
$pubKeyConf | Set-Content -Path C:\ProgramData\ssh\sshd_config | |
$passwordConf = (Get-Content -path C:\ProgramData\ssh\sshd_config) -replace '#PasswordAuthentication yes','PasswordAuthentication yes' | |
$passwordConf | Set-Content -Path C:\ProgramData\ssh\sshd_config | |
$authorizedKeyFilePath = "$env:ProgramData\ssh\administrators_authorized_keys" | |
New-Item -Force $authorizedKeyFilePath | |
echo "YOUR KEY HERE" | Out-File $authorizedKeyFilePath -Encoding ascii | |
$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys | |
$acl.SetAccessRuleProtection($true, $false) | |
$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow") | |
$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow") | |
$acl.SetAccessRule($administratorsRule) | |
$acl.SetAccessRule($systemRule) | |
$acl | Set-Acl | |
Restart-Service sshd | |
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\hns\State' -Name DeviceLessNicDisabled -PropertyType DWORD -Value 1 -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment