SSH Key - Still asking for password and passphrase

后端 未结 30 1365
孤街浪徒
孤街浪徒 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:12

    Same problem to me and the solution was:

    See this github doc to convert remote's URL from https to ssh. To check if remote's URL is ssh or https, use git remote -v. To switch from https to ssh: git remote set-url origin git@github.com:USERNAME/REPOSITORY.git @jeeYem

    0 讨论(0)
  • 2020-11-27 09:13

    If you work with HTTPs urls, it'll always ask for your username / password.

    If you're correctly using SSH when cloning / setting remotes. Then make sure you have a ssh-agent to remember your password. That way, you'll only enter your passphrase once by terminal session.

    If it is still too annoying, then simply set a ssh-key without passphrase.

    0 讨论(0)
  • 2020-11-27 09:13

    You can remove passphrase for the key

    $ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
    

    or you can run

    $ ssh-keygen -p
    

    you get a prompt for keyfile. By default it ~/.ssh/id_rsa so press enter

    You'll be prompted for current pass phrase enter it.

    Then there will be a prompt for new pass phrase, press enter

    0 讨论(0)
  • 2020-11-27 09:14

    TL;DR
    You need to use an ssh agent. So, open terminal & try

    ssh-add
    

    before pushing to git. Enter your passphrase when prompted.

    Check out the original StackExchange answer here

    0 讨论(0)
  • 2020-11-27 09:15

    On Mac OSX you can add your private key to the keychain using the command:

    ssh-add -K /path/to/private_key
    

    If your private key is stored at ~/.ssh and is named id_rsa:

    ssh-add -K ~/.ssh/id_rsa
    

    You will then be prompted for your password, which will be stored in your keychain.

    Edit - Handle restart

    In order to not have to fill in your password even after a restart add the following to your ssh configuration file (commonly located at ~/.ssh/config)

    Host *
      UseKeychain yes
      AddKeysToAgent yes
      IdentityFile ~/.ssh/id_rsa
    
    0 讨论(0)
  • 2020-11-27 09:15

    This answer is primarily for windows users and also equally relevant if you're having trouble cloning with tfs, github or gitlab on any other OS.

    The default authentication mode when using SSH is the private key. Whenever that fails for some reason, the ssh-agent falls back to username and password based authentication.

    There are several reasons why the default key based authentication might have failed. Following are the most common cases :

    a) The ssh-agent cannot find the default private key file which is id_rsa, and no other key path is specified explicitly.

    b) The public key stored in the server is incorrect.

    c) The path you're trying to clone is incorrect.

    In any case, to troubleshoot the issue, first of all execute the git clone command with verbose logging with the command :

    GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git clone ssh://pathToYourRepo
    

    You can go through each step in the log to get an intuition of what the issue might be.


    Troubleshooting in case of (a)

    • Make sure you have the default key name id_rsa in the .ssh directory. You might have specified some different keyname when generating the key with ssh-keygen command or maybe there isn't any key at all).

    • In case you want to specify a different key for authentication, use the following command :

       ssh-agent bash -c 'ssh-add ~/.ssh/anotherKey; git clone ssh://pathToYourRepo'
      

    Troubleshooting in case of (b)

    • Make sure there aren't extra white spaces when storing the public key in the server.

    Troubleshooting in case of (c)

    • Make sure you aren't trying to clone with the https version of the repository path.
    0 讨论(0)
提交回复
热议问题