Skip to content

Instantly share code, notes, and snippets.

@gorshkov-leonid
Last active August 15, 2023 18:19
Show Gist options
  • Save gorshkov-leonid/6d71060e32da19b6530fdc5df2e4b494 to your computer and use it in GitHub Desktop.
Save gorshkov-leonid/6d71060e32da19b6530fdc5df2e4b494 to your computer and use it in GitHub Desktop.
ssh for github in windows

WSL

Generating key pair

ssh-keygen -t ed25519 -C "[email protected]"

See gitub.com: Generating a new SSH key and adding it to the ssh-agent:

Key/pub will be here ~\.ssh and will look like id_ed25519 and id_ed25519.pub

(optional) Run SSH agent on Windows startup using Task Scheduler (taskschd.msc)

$task = New-ScheduledTaskAction -Execute "C:\Windows\System32\wsl.exe" -Argument '-u root bash -c "ssh-agent -s && sleep 3"'
$trigger = New-ScheduledTaskTrigger -AtLogon
$settings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
Register-ScheduledTask RunSshAgent -Action $task -Trigger $trigger -Settings $settings

Windows

Install Open SSH Client if ssh-agent is unavailable

  • Open Windows Settings
  • Apps -> Apps & features -> Optional Features -> [+] Add Feature.
  • Choose OpenSSH Client and install it.

Generating ket pair

# Set the sshd service to be started automatically
Get-Service -Name ssh-agent | Set-Service -StartupType Automatic
ssh-keygen -t ed25519 -C  "[email protected]"

See microsoft.com: Управление ключами OpenSSH

Key/pub will be here C:\Users\<user-id>\.ssh and will look like id_ed25519 and id_ed25519.pub

Use authentication with public key per host

see gitlab: Configure SSH to point to a different directory

Edit ~/.ssh/config (or %USERPROFILE%/.ssh/config in Windows)

Host <company-git-host>
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/<corp-private-key-filename>
  
Host github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/<github-private-key-filename>

Update remote URL to use SSH

git remote set-url origin git@<host>:<user>/<path>.git or git remote set-url origin git@<host>:<path>.git

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