Skip to content

Instantly share code, notes, and snippets.

@ZilchBloke
Last active April 20, 2023 05:39
Show Gist options
  • Save ZilchBloke/6e0531d38992790fb68350cf43cb7264 to your computer and use it in GitHub Desktop.
Save ZilchBloke/6e0531d38992790fb68350cf43cb7264 to your computer and use it in GitHub Desktop.

ssh-agent

For Windows:
Use Powershell (7.3 and above as an admin).
By default the ssh-agent service is disabled.
Configure it to start automatically.
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start the service
Start-Service ssh-agent

For Linux:
eval $(ssh-agent)

This should return a status of Running

Get-Service ssh-agent

Now load your key files into ssh-agent

ssh-add $env:USERPROFILE\.ssh\key_file

To lists the public keys of all identities currently managed by the ssh-agent

ssh-add -L

Note that when you create the ~/.ssh/config file you may need to run:
chmod 600 ~/.ssh/configOR chown $USER ~/.ssh/config
Otherwise, you might receive the Bad owner or permissions on ~/.ssh/config error.

To delete all identities from the ssh-agent.

ssh-add -D

Use Manual for more information and usages.

man ssh-add

Use scp to secure copy public_key.pub from linux to windows.

For Administrator:

If you are doing this the first time then you will have to create the administrator_authorized_keys file(step 3). If you have already created this file, make sure you have the permissions set correctly (step 4).

  1. Copy the public key from linux client to windows server:
    scp ~/.ssh/public_key.pub windowsUser@windowsMachine:'__PROGRAMDATA__/ssh/'
  2. ssh into windows server and check if there is administrators_authorized_keys file present in C:\PROGRAMDATA\SSH\
  3. If not, Create:
    New-Item -Force -Path c:\PROGRAMDATA\ssh\administrators_authorized_keys
  4. Set Permissions for administrators_authorized_keys file:
    icacls C:\PROGRAMDATA\ssh\administrators_authorized_keys /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
  5. Append public_key.pub content into administrator_authorized_keys.
    Get-Content C:\ProgramData\ssh\public_key.pub | Add-Content C:\ProgramData\ssh\administrators_authorized_keys

For Normal User:

scp ~/.ssh/public_key.pub windowsUser@windowsMachine:'$env:USERPROFILE\.ssh\authorized_keys'

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