Skip to content

Instantly share code, notes, and snippets.

@rhom6us
Last active August 3, 2024 00:47
Show Gist options
  • Save rhom6us/dfdd4aeabdb8ce138a53d19141b7c0c0 to your computer and use it in GitHub Desktop.
Save rhom6us/dfdd4aeabdb8ce138a53d19141b7c0c0 to your computer and use it in GitHub Desktop.
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@[email protected] $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@[email protected] $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