Overview
Automation needs to connect to servers without someone typing a password. Key-based SSH does that securely: the server trusts your public key, and only the holder of the private key can sign in. Use an Ed25519 key unless an old system needs RSA.
Key type
Ed25519 (RSA 3072+ only for old systems)From
LinuxTo
Linux, or Windows Server with OpenSSHStep 1: Create a key on the source server
ssh-keygen -t ed25519 -C "automation@source-server"
Press Enter to accept the default file (~/.ssh/id_ed25519). For an unattended automation key you can leave the passphrase empty, but then protect the file: it is a credential.
Step 2a: Linux destination
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@destination-server
ssh user@destination-server
ssh-copy-id asks for the password once and adds the key to ~/.ssh/authorized_keys. The second command should sign you in without a password.
Step 2b: Windows Server destination
- Install and start the OpenSSH server (PowerShell as Administrator):
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
- Add the public key (the contents of
id_ed25519.pub):- for a standard user: as a line in
C:\Users\<user>\.ssh\authorized_keys; - for a user in the Administrators group: as a line in
C:\ProgramData\ssh\administrators_authorized_keys, then set its permissions:
- for a standard user: as a line in
icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
Add the key to the file rather than overwriting it, so existing keys keep working. 3. Test from the Linux server:
ssh Administrator@windows-server
If it still asks for a password
- On Linux,
~/.sshmust be700andauthorized_keys600, owned by the user. - On Windows, check the file permissions above and the OpenSSH/Operational log in Event Viewer.
- Run
ssh -v user@serverto see which keys are offered and why they are refused.