How to prevent ssh key passphrase prompt every time you launch WSL (2024)

How to prevent ssh key passphrase prompt every time you launch WSL (2)

I am assuming you already know about SSH, used SSH key with passphrase and got annoyed for seeing password prompt for your key every time you launch WSL and stumbled upon my post while searching for a solution to get rid of this.

In Linux, you can run ssh-add <your key location> and then the SSH authentication agent stores your key safely and you never need to type your passphrase again. This doesn’t work on WSL. It works only as long as your terminal session is running. Once you close it, or open a new window, you need to add it again or type the passphrase every time. There are some workaround solutions, custom scripts I have found on other people’s solutions, but they all require you to type the passphrase at least once after you reboot your computer. I don’t like it. I have figured out another solution that doesn’t need that.

If you didn’t know, Windows 10 and 11 now comes with OpenSSH built-in. If you save your SSH key on windows’ SSH authentication agent, that is persisted. So my solution is to share the SSH service of Windows with WSL!

Key Generation

If you already have your key, move it to the default location C:\Users\<username>\.ssh folder, or somewhere you want, and skip to the Key Storing part. If you want to generate a new key pair, follow this part.

First you need to have OpenSSH-server. The client comes pre-installed but you might need to install the server manually. Lets check if you have it installed already. For Windows 10, go to ‘Settings > Apps > Apps & Features > Optional Features’ (update: this seems to have moved to ‘Settings > System > Optional Features’) or for Windows 11 go to ‘Settings > Apps > Optional Features’ and search ‘ssh’, if you see server, you have it, if not, lets install it.

How to prevent ssh key passphrase prompt every time you launch WSL (3)

Click the ‘View features’ button on ‘Add an optional feature’ option (Windows 11) or ‘Add a feature’ (Windows 10), search for the server and install it.

After installing it, run PowerShell as Administrator, and run the following code,

Get-Service ssh-agent | Set-Service -StartupType AutomaticStart-Service sshdssh-keygen #add additional parameters here as you like

This will generate your new Public-Private key pair. The default location where the files will be saved is C:\Users\<username>\.ssh .

Key Storing

To save the key in ssh authentication agent, run the following code in PowerShell as Administrator,

Get-Service ssh-agent | Set-Service -StartupType AutomaticStart-Service ssh-agentGet-Service ssh-agent

ssh-add <key file location>

This will prompt you to type your key passphrase. Enter it and you are done!

Let’s check if it asks again when you try to use the ssh key. Add the public key to your Github account (open <your key>.pub with any text editor to copy the key), and then run the following on your Windows machine’s terminal, (cmd or powershell)

ssh -T [email protected]

You should get Hello from Github without needing your passphrase.

Configuring WSL

Now it’s time to tell WSL to use Windows’ SSH client. We can explicitly tell git to use Windows’ ssh, by running,

git config --global core.sshcommand "ssh.exe"

If you test your connection with Github again, now from WSL, you will see you are not asked for your passphrase!

And to use it for other ssh connection from WSL, instead of typing ssh user@host , type ssh.exe user@host and you will be using the ssh service from Windows! If you don’t like to type .exe, you can set an alias for it in your ~/.bash_aliases or equivalent file,

alias ssh='ssh.exe'#linux distro's ssh if you want
#alias sshw='/usr/bin/ssh'
# I guess there is a better way to rename it other than setting alias?

WSL2 is one of the best things Windows have offered. You now can use the best of the both worlds in a single machine, without needing to switch OS. Combine that with Windows Terminal (which now comes pre-installed with Windows 11, downloadable from Microsoft Store for Windows 10), you now have a powerful developer machine.

(If you found this article helpful, give it some claps! If you want to connect with me, send me a request on Twitter@AhsanShihab_.)

How to prevent ssh key passphrase prompt every time you launch WSL (2024)

FAQs

How to avoid ssh from prompting key passphrase? ›

Now, to avoid entering the SSH key passphrase every time:
  1. You will need to use an SSH agent of some kind. For Windows: You will use the OpenSSH Authentication Agent. ...
  2. At your command line prompt, in either case, type ssh-add. If you used the default id_rsa naming for your key, that's all you have to do.
Jun 24, 2024

How to disable SSH key passphrase? ›

Remove the passphrase: Use the `ssh-keygen` command to remove the passphrase from the key. The `-p` flag is used for changing the passphrase of a private key file. You'll be prompted to enter the old passphrase and then leave the new passphrase field blank.

Why does my SSH key keep prompting for a password? ›

The most common causes for this are incorrect permissions on the . ssh folder or key files (authorized_keys, id_rsa, and other private key files).

How to avoid password prompt in ssh? ›

5 Steps to Configure SSH Without a Password
  1. Verify That the SSH Server Is Running.
  2. Connect to Remote Machine.
  3. Generate Private and Public Keys.
  4. Copy the Public Key File to the Remote Machine.
  5. Login to Your Server Using SSH Keys.
Feb 20, 2024

Why is SSH asking for key passphrase? ›

With SSH keys, if someone gains access to your computer, the attacker can gain access to every system that uses that key. To add an extra layer of security, you can add a passphrase to your SSH key. To avoid entering the passphrase every time you connect, you can securely save your passphrase in the SSH agent.

How do I get rid of SSH warning? ›

To prevent the warning message from recurring, use one of the following methods:
  1. Remove the outdated host key using ssh-keygen . Run the following command to remove the host fingerprint for the previous hardware: ...
  2. Edit or remove the known_hosts file. ...
  3. Turn off StrictHostKeyChecking.
Aug 16, 2024

How do I avoid key checking in SSH? ›

Solution 3: Use SSH key options to bypass verification

There are two SSH key options that you can use to bypass the verification process: -o UserKnownHostsFile= and -o StrictHostKeyChecking= . These options can be used in the SSH command or in the SSH configuration file.

How to disable SSH password authentication? ›

Disable Password Authentication
  1. vim /etc/ssh/sshd_config. Look for the line PasswordAuthentication yes and replace yes with no.
  2. PasswordAuthentication no. Press ESC key and save the changes to the file and exit the editor by typing: wq! and then hit Enter. ...
  3. service sshd restart.

How to disable key based authentication SSH? ›

Disable public key authentication in SSH
  1. Log into SSH.
  2. Edit the file with your favorite editor: /etc/ssh/sshd_config.
  3. Lookup the variable: PasswordAuthentication and change 'no' to 'yes'
  4. Save and close the file.
  5. Run this command: service sshd reload.

How to set passwordless SSH in Ubuntu? ›

How to Setup Passwordless SSH on Linux (Ubuntu 22.04)?
  1. Step 1: Refresh and Update Package List. ...
  2. Step 2: Install OpenSSH via APT. ...
  3. Step 3: Check SSH Status. ...
  4. Step 1: Generate Public Key Pair. ...
  5. Step 2: Transfer the Generated Key to Remote Server. ...
  6. Step 3: Test SSH. ...
  7. Step 1: Setup Passwordless SSH. ...
  8. Step 2: Restart SSH Service.
Feb 13, 2024

How to disable password prompt for user in Linux? ›

To disable the password prompt, you can edit this file.
  1. Step 1: Open the sudoers file for editing: sudo visudo.
  2. Step 2: Find the Defaults line. In the sudoers file, locate the line that starts with Defaults .
  3. Step 3: Add a line to disable the password prompt. ...
  4. Step 4: Save and exit the editor.
Nov 10, 2023

How do I protect my SSH key? ›

To tighten security controls around SSH keys, you should also apply the following 10 best practices:
  1. Discover all SSH Keys and Bring Under Active Management. ...
  2. Change Default SSH Port. ...
  3. Disable SSH Root Login. ...
  4. Implement Two-Factor Authentication. ...
  5. Ensure SSH Key Attribution. ...
  6. Enforce Minimal Levels of User Rights Through PoLP.
Nov 22, 2022

How do I stop Git from asking for my passphrase? ›

You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.

Top Articles
FINMA - an independent supervisory authority
How to Create a Cryptocurrency Mining Pool with Development Services?
9.4: Resonance Lewis Structures
What to Do For Dog Upset Stomach
Identifont Upload
Arkansas Gazette Sudoku
Sarah F. Tebbens | people.wright.edu
Marist Dining Hall Menu
Midway Antique Mall Consignor Access
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Hartford Healthcare Employee Tools
Https E24 Ultipro Com
104 Whiley Road Lancaster Ohio
Busby, FM - Demu 1-3 - The Demu Trilogy - PDF Free Download
Golden Abyss - Chapter 5 - Lunar_Angel
Dover Nh Power Outage
Quick Answer: When Is The Zellwood Corn Festival - BikeHike
Great Clips Grandview Station Marion Reviews
Rs3 Ushabti
Olivia Maeday
Www Pointclickcare Cna Login
Cal State Fullerton Titan Online
Vht Shortener
Black Lion Backpack And Glider Voucher
Play It Again Sports Forsyth Photos
Tu Housing Portal
Kleinerer: in Sinntal | markt.de
Pay Stub Portal
United E Gift Card
Inmate Search Disclaimer – Sheriff
Abga Gestation Calculator
Craigslist Cars And Trucks Mcallen
New Gold Lee
Greater Keene Men's Softball
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Woodman's Carpentersville Gas Price
The Minneapolis Journal from Minneapolis, Minnesota
What Does Code 898 Mean On Irs Transcript
Ukraine-Krieg - Militärexperte: "Momentum bei den Russen"
Mybiglots Net Associates
Wgu Admissions Login
The Sports Academy - 101 Glenwest Drive, Glen Carbon, Illinois 62034 - Guide
Dobratz Hantge Funeral Chapel Obituaries
All Buttons In Blox Fruits
Barback Salary in 2024: Comprehensive Guide | OysterLink
St Als Elm Clinic
Unpleasant Realities Nyt
Rocket Bot Royale Unblocked Games 66
Hy-Vee, Inc. hiring Market Grille Express Assistant Department Manager in New Hope, MN | LinkedIn
Vt Craiglist
All Obituaries | Roberts Funeral Home | Logan OH funeral home and cremation
login.microsoftonline.com Reviews | scam or legit check
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 5633

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.