Skip to content

Instantly share code, notes, and snippets.

@HacDan
Last active November 9, 2023 00:12
Show Gist options
  • Save HacDan/026fa8d7d4130fbbc2409d84c2d04143 to your computer and use it in GitHub Desktop.
Save HacDan/026fa8d7d4130fbbc2409d84c2d04143 to your computer and use it in GitHub Desktop.

How to install SSH and Load Public Keys

Install OpenSSH Server

  1. Open Admin PowerShell
  2. Run the following command
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  1. Enable the services
Set-Service -Name ssh-agent -StartupType `Automatic`
Set-Service -Name sshd -StartupType `Automatic`
  1. Start both services
Start-Service ssh-agent
Start-Service sshd

Load Public Keys

  1. Public keys go here C:\ProgramData\ssh\administrators_authorized_keys
  2. Remove AuthenticatedUsers permission from aforementioned file C:\ProgramData\ssh\administrators_authorized_keys

Edit OpenSSH Config to allow Pubkey Authentication

  1. Open C:\ProgramData\ssh\sshd_config
  2. Change the line that says #PubkeyAuthentication to remove the Pound Sign (Hash Tag for you youngins)
  3. Change the line that says #PasswordAuthentication yes to PasswordAuthentication no (And remove the Pound Sign)
  4. Save the file

Change Default Shell

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

IF YOU CANNOT REBOOT - Restart Services

Restart both services to avoid a reboot of the computer

Restart-Service ssh-agent
Restart-Service sshd

Source

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