SSH Key - Still asking for password and passphrase

后端 未结 30 1442
孤街浪徒
孤街浪徒 2020-11-27 08:35

I\'ve been somewhat \'putting up\' with Github always asking for my username and password when I clone a repository. I want to bypass this step because it is an annoyance w

30条回答
  •  我在风中等你
    2020-11-27 09:10

    SSH Key - Still asking for password and passphrase

    If on Windows and using PuTTY as the SSH key generator, this quick & easy solution turned out to be the only working solution for me using a plain windows command line:

    1. Your PuTTY installation should come with several executable, among others, pageant.exe and plink.exe
    2. When generating a SSH key with PuttyGen, the key is stored with the .ppk extension
    3. Run "full\path\to\your\pageant.exe" "full\path\to\your\key.ppk" (must be quoted). This will execute the pageant service and register your key (after entering the password).
    4. Set environment variable GIT_SSH=full\path\to\plink.exe (must not be quoted). This will redirect git ssh-communication-related commands to plink that will use the pageantservice for authentication without asking for the password again.

    Done!

    Note1: This documentation warns about some peculiarities when working with the GIT_SHH environment variable settings. I can push, pull, fetch with any number of additional parameters to the command and everything works just fine for me (without any need to write an extra script as suggested therein).

    Note2: Path to PuTTY instalation is usually in PATH so may be omitted. Anyway, I prefer specifying the full paths.

    Automation:

    The following batch file can be run before using git from command line. It illustrates the usage of the settings:

    git-init.bat
       @ECHO OFF
       :: Use start since the call is blocking
       START "%ProgramFiles%\PuTTY\pageant.exe" "%HOMEDRIVE%%HOMEPATH%\.ssh\id_ed00000.ppk"
       SET GIT_SSH=%ProgramFiles%\PuTTY\plink.exe
    

    Anyway, I have the GIT_SSH variable set in SystemPropertiesAdvanced.exe > Environment variables and the pageant.exe added as the Run registry key (*).

    (*) Steps to add a Run registry key>

    1. run regedit.exe
    2. Navigate to HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Run
    3. Do (menu) Edit > New > String Value
    4. Enter an arbitrary (but unique) name
    5. Do (menu) Edit > Modify... (or double-click)
    6. Enter the quotes-enclosed path to pageant.exe and public key, e.g., "C:\Program Files\PuTTY\pageant.exe" "C:\Users\username\.ssh\id_ed00000.ppk" (notice that %ProgramFiles% etc. variables do not work in here unless choosing Expandable string value in place of the String value in step 3.).

提交回复
热议问题