This guide explains how to generate an SSH key pair in Windows, configure a remote Linux server to accept it, and connect securely using VS Code.
Step 1: Generate the SSH Key Pair on Windows
Open PowerShell on your local windows machine and run the following commands to create a secure ED25519 key pair:
|
1 2 |
cd C:\Users\user\.ssh ssh-keygen -t ed25519 -C "developer1" |
When prompted, customize the filename to keep it organized:
- Generating public/private ed25519 key pair.
- Enter file in which to save the key (C:\Users\user/.ssh/id_ed25519): vscode
- Enter passphrase (empty for no passphrase): [Press Enter]
- Enter same passphrase again: [Press Enter]
Your keys are saved in your local .ssh directory:
Private Key: C:\Users\user\.ssh\vscode (Keep this secret)
Public Key: C:\Users\user\.ssh\vscode.pub (Share this with the server)
Copy the Public Key to the Linux Server:
To authorize your key, you need to append the contents of your public key (vscode.pub) to the authorized_keys file on your remote Linux server.
View your public key content on Windows:
|
1 |
Get-Content .\vscode.pub |
Output example:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHlwDP9mhzkAp203mH3zs1YTLA4klmTDV4YYhTrj7sx/ developer1
Log into your remote Linux server and open (or create) the authorized_keys file inside your remote user’s .ssh/ directory:
Paste the public key string into ssh/ directory and rename it to:
|
1 |
authorized_keys |
Set the correct permissions on the server (if needed):
|
1 2 |
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys |
Configure VS Code Remote-SSH:
Open your local VS Code SSH configuration file (typically located at C:\Users\user\.ssh\config) and add the following host entry:
|
1 2 3 4 5 |
Host mysite.com HostName mysite.com User mysite Port 22 IdentityFile "C:\Users\user\.ssh\vscode" |
You can now open VS Code, click on the Remote Explorer, select mysite.com, and connect seamlessly without entering a password.
