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
)
Get-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\key_file
ssh-add -L
Note that when you create the ~/.ssh/config file you may need to run:
chmod 600 ~/.ssh/config
ORchown $USER ~/.ssh/config
Otherwise, you might receive theBad owner or permissions on ~/.ssh/config
error.
ssh-add -D
man ssh-add
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).
- Copy the public key from linux client to windows server:
scp ~/.ssh/public_key.pub windowsUser@windowsMachine:'__PROGRAMDATA__/ssh/'
- ssh into windows server and check if there is
administrators_authorized_keys
file present inC:\PROGRAMDATA\SSH\
- If not, Create:
New-Item -Force -Path c:\PROGRAMDATA\ssh\administrators_authorized_keys
- Set Permissions for
administrators_authorized_keys
file:
icacls C:\PROGRAMDATA\ssh\administrators_authorized_keys /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
- 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
scp ~/.ssh/public_key.pub windowsUser@windowsMachine:'$env:USERPROFILE\.ssh\authorized_keys'