🔐 Recreate an SSH Key in WSL and Deploy It to Servers
This guide explains how to regenerate an SSH key inside a WSL instance after deleting it, and how to configure remote servers to accept this new key.
1. Generate a New SSH Key Pair
- Open a terminal in your WSL instance.
- Run the following command:
ssh-keygen -t ed25519 -C "your.email@example.com"
-t ed25519: modern and secure key type (recommended).-C: comment to identify the key (optional but useful).
- When prompted:
- File location: press
Enterto accept the default~/.ssh/id_ed25519path. - Passphrase: optional but recommended for added security (for automation, don't set it).
- File location: press
This creates two files:
~/.ssh/id_ed25519→ private key~/.ssh/id_ed25519.pub→ public key
2. Start the SSH Agent and Add the Key
To make the key available automatically:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Verify the key is loaded:
ssh-add -l
3. Copy the Public Key to Remote Servers
For each remote server you want to configure, run:
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
💡 If
ssh-copy-idis not available in your WSL, copy the key manually:
cat ~/.ssh/id_ed25519.pub
Then, on the remote server:
- Connect using password
- Append the public key content to
~/.ssh/authorized_keys - Ensure correct permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
4. Test the Connection
From your WSL:
ssh user@server
If everything is configured correctly, you should connect without entering a password.
5. (Optional) Configure ~/.ssh/config
To simplify connections, create or edit the ~/.ssh/config file:
nano ~/.ssh/config
And add:
Host my-server
HostName server.address
User user
IdentityFile ~/.ssh/id_ed25519
You can then connect with:
ssh my-server
✅ Summary
- Generate SSH key (
ssh-keygen) - Start the agent and add the key (
ssh-agent+ssh-add) - Copy the public key to servers (
ssh-copy-idor manual) - Test and optionally configure
~/.ssh/config
⚠️ Important: Never share your private key (
id_ed25519).
It must stay only on your local machine.