Set Up SSH Key Authentication on Ubuntu
SSH key authentication allows you to connect to a server without using the account password.
For new keys, Ed25519 is recommended.
Generate an SSH Key on Windows
Open PowerShell:
Press Enter to use the default location.
The files will normally be created under:
Two files are created:
id_ed25519 is the private key and should never be shared.
id_ed25519.pub is the public key that is added to the server.
Display the Public Key
Copy the complete public key.
Add the Public Key to the Server
For root:
Open:
Paste the public key on a new line.
Then set the correct permissions:
SSH Configuration
Open:
Example:
Replace:
with the SSH port configured on the server.
Root Login
allows root login using an SSH key while preventing password-based root login.
Combined with:
SSH authentication will use keys instead of passwords.
If direct root SSH access is not required, use:
and connect with a normal sudo-enabled user instead.
Test the Configuration
Always check the configuration before applying changes:
If no output is returned, the configuration syntax is valid.
To view the effective SSH configuration:
Apply the Configuration
Check the service:
Firewall
If using a custom SSH port, make sure it is allowed through UFW:
Check:
Test the New Connection
Keep the existing SSH connection open while testing.
From another PowerShell window:
If the key needs to be specified manually:
Only close the original SSH session after confirming the new key-based connection works.