Last active
March 25, 2026 07:28
-
-
Save fnrhombus/dfdd4aeabdb8ce138a53d19141b7c0c0 to your computer and use it in GitHub Desktop.
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
| if((Get-WindowsCapability -Online | Where-Object Name -like "OpenSSH.Server*").State -ne "Installed") { | |
| Add-WindowsCapability -Online -Name "OpenSSH.Server" | |
| } | |
| $sshServer = Get-Service sshd | |
| $sshServer | Set-Service -StartupType 'Automatic' | |
| $sshServer | Start-Service | |
| # This should return a status of Running | |
| if($sshServer.Status -ne 'Running') { | |
| throw 'wtf mate' | |
| } | |
| $sshAgent = Get-Service ssh-agent | |
| $sshAgent | Set-Service -StartupType 'Automatic' | |
| $sshAgent | Start-Service | |
| # This should return a status of Running | |
| if($sshAgent.Status -ne 'Running') { | |
| throw 'wtf mate' | |
| } | |
| ssh-keygen -t ed25519 -f $env:USERPROFILE\.ssh\id_ed25519 -N "" | |
| ssh-add $env:USERPROFILE\.ssh\id_ed25519 | |
| ##################### DO THIS ##################### | |
| #WARNING: this copys all keys from the agent. See command line help to stop this. | |
| ssh-copy-id [user]@[ip-address] | |
| ##################### OR THIS ##################### | |
| #THIS SETS UP A STANDARD USER | |
| $authorizedKey = Get-Content -Path $env:USERPROFILE\.ssh\id_ed25519.pub | |
| $remotePowershell = "powershell New-Item -Force -ItemType Directory -Path $env:USERPROFILE\.ssh; Add-Content -Force -Path $env:USERPROFILE\.ssh\authorized_keys -Value '$authorizedKey'" | |
| ssh username@domain1@contoso.com $remotePowershell | |
| ##################### OR THIS ##################### | |
| #THIS SETS UP AN ADMIN | |
| $authorizedKey = Get-Content -Path $env:USERPROFILE\.ssh\id_ed25519.pub | |
| $remotePowershell = "powershell Add-Content -Force -Path $env:ProgramData\ssh\administrators_authorized_keys -Value '''$authorizedKey''';icacls.exe ""$env:ProgramData\ssh\administrators_authorized_keys"" /inheritance:r /grant ""Administrators:F"" /grant ""SYSTEM:F""" | |
| $remotePowerShell variable | |
| ssh username@domain1@contoso.com $remotePowershell | |
| ##################### OR THIS ##################### | |
| #THIS IS FOR LINUS HOSTS WITHOUT POWERSHELL | |
| cat ~/.ssh/id_ed25519.pub | ssh user@server "cat >> ~/.ssh/authorized_keys" | |
| ################################################# | |
| *9******** | |
| Get-Service -Name sshd | Set-Service -StartupType Automatic | |
| Start-Service sshd | |
| ssh-keygen -t ed25519 | |
| # Make sure you're running as an Administrator. | |
| Get-Service ssh-agent | Set-Service -StartupType Automatic | |
| Start-Service ssh-agent | |
| # This should return a status of Running | |
| Get-Service ssh-agent | |
| ssh-add $env:USERPROFILE\.ssh\id_ed25519 | |
| ##################### DO THIS ##################### | |
| #WARNING: this copys all keys from the agent. See command line help to stop this. | |
| ssh-copy-id [user]@[ip-address] | |
| ##################### OR THIS ##################### | |
| #THIS SETS UP A STANDARD USER | |
| $authorizedKey = Get-Content -Path $env:USERPROFILE\.ssh\id_ed25519.pub | |
| $remotePowershell = "powershell New-Item -Force -ItemType Directory -Path $env:USERPROFILE\.ssh; Add-Content -Force -Path $env:USERPROFILE\.ssh\authorized_keys -Value '$authorizedKey'" | |
| ssh username@domain1@contoso.com $remotePowershell | |
| ##################### OR THIS ##################### | |
| #THIS SETS UP AN ADMIN | |
| $authorizedKey = Get-Content -Path $env:USERPROFILE\.ssh\id_ed25519.pub | |
| $remotePowershell = "powershell Add-Content -Force -Path $env:ProgramData\ssh\administrators_authorized_keys -Value '''$authorizedKey''';icacls.exe ""$env:ProgramData\ssh\administrators_authorized_keys"" /inheritance:r /grant ""Administrators:F"" /grant ""SYSTEM:F""" | |
| $remotePowerShell variable | |
| ssh username@domain1@contoso.com $remotePowershell | |
| ##################### OR THIS ##################### | |
| #THIS IS FOR LINUS HOSTS WITHOUT POWERSHELL | |
| cat ~/.ssh/id_ed25519.pub | ssh user@server "cat >> ~/.ssh/authorized_keys" | |
| ################################################# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment