SSH Key - Still asking for password and passphrase

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

    Problem seems to be because you're cloning from HTTPS and not SSH. I tried all the other solutions here but was still experiencing problems. This did it for me.

    Using the osxkeychain helper like so:

    1. Find out if you have it installed.

      git credential-osxkeychain

    2. If it's not installed, you'll be prompted to download it as part of Xcode Command Line Tools.

    3. If it is installed, tell Git to use osxkeychain helper using the global credential.helper config:

      git config --global credential.helper osxkeychain

    The next time you clone an HTTPS url, you'll be prompted for the username/password, and to grant access to the OSX keychain. After you do this the first time, it should be saved in your keychain and you won't have to type it in again.

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

    If you are using Windows and GIT without third party tools and your key is not secured by a password / passphrase use this:

    1. Environment Variable HOME must be set to your user profile (e.g. C:\Users\Laptop)
    2. Go to C:\Users\Laptop\.ssh\ folder and edit "config" file (or create the file!) Example: C:\Users\Laptop.ssh\config (note: there is no . at the end!)
    3. Add your git-server host to the "config" file like so:

      #Example host entry
      Host myhostname.com
          HostName myhostname.com
          User git
          IdentityFile c:/users/laptop/.ssh/id_rsa.pub
          PasswordAuthentication no
          Port 422
      
    4. Save the file and clone the repository like this:

      git clone ssh://myhostname.com/git-server/repos/picalc.git

    You can use additional configuration parameters for the "config" file host entry. These can be found in your local git installation folder, e.g. "C:\Program Files\Git\etc\ssh\ssh_config". Excerpt:

    # Host *
    #   ForwardAgent no
    #   ForwardX11 no
    #   RhostsRSAAuthentication no
    #   RSAAuthentication yes
    #   PasswordAuthentication yes
    #   HostbasedAuthentication no
    #   GSSAPIAuthentication no
    #   GSSAPIDelegateCredentials no
    #   BatchMode no
    #   CheckHostIP yes
    #   AddressFamily any
    #   ConnectTimeout 0
    #   StrictHostKeyChecking ask
    #   IdentityFile ~/.ssh/identity
    #   IdentityFile ~/.ssh/id_rsa
    #   IdentityFile ~/.ssh/id_dsa
    #   IdentityFile ~/.ssh/id_ecdsa
    #   IdentityFile ~/.ssh/id_ed25519
    #   Port 22
    #   Protocol 2
    #   Cipher 3des
    #   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
    #   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
    #   EscapeChar ~
    #   Tunnel no
    #   TunnelDevice any:any
    #   PermitLocalCommand no
    #   VisualHostKey no
    #   ProxyCommand ssh -q -W %h:%p gateway.example.com
    #   RekeyLimit 1G 1h
    
    0 讨论(0)
  • 2020-11-27 09:18

    For Mac OSX Sierra, I found that the fixes suggested in the github issue for Open Radar fixed my problem. Seems like Sierra changed the default behavior (I started having this problem after upgrading).

    This one I found especially useful: https://github.com/lionheart/openradar-mirror/issues/15361#issuecomment-249059061

    ssh-add -A 
    

    This resulted in my identity being added to the agent, after I ran

    ssh-add -K {/path/to/key}
    

    To summarize, in OSX.12:

    ssh-add -K {/path/to/key}
    ssh-add -A 
    

    should result in:

    Identity added: {/path/to/file} ({/path/to/file})
    

    EDIT: I noticed the next time I did a full reboot (aka the agent stopped and restarted) this no longer worked. The more complete solution is what @ChrisJF mentioned above: creating a ~/.ssh/config file. Here's the output of mine:

    $ cat ~/.ssh/config
    Host *
      UseKeychain yes
      AddKeysToAgent yes
      IdentityFile ~/.ssh/id_rsa
    

    You can add as many IdentityFile entries as you need, but this is the default setup. This is the "trending" answer on the openradar link above, ATM, as well.

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

    I tried all the answers here and none of these answers worked! My password would not persist between sessions/restarts of my Mac.

    What I found out from reading this OpenRadar and this Twitter discussion was that Apple purposely changed the behaviour for ssh-agent in macOS 10.12 Sierra to no longer automatically load the previous SSH keys. In order to maintain the same behaviour as El Cap I did the following:

    1. ssh-add -K ~/.ssh/id_rsa
      Note: change the path to where your id_rsa key is located.
    2. ssh-add -A
    3. Create (or edit if it exists) the following ~/.ssh/config file:

      Host *
        UseKeychain yes
        AddKeysToAgent yes
        IdentityFile ~/.ssh/id_rsa
      

    And now my password is remembered between restarts of my Mac!

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

    I'd like to add an answer for those who may still need to enter the password because they have set IdentitiesOnly as yes. This may cause by multiple keys and the identity file, being keys for git or server.

    After I have generated the key and copied it to the server:

    ssh-keygen
    ssh-copy-id -i ~/.ssh/12gpu_server.pub lerner@192.168.20.160
    

    I found it didn't work.

    Then I went to check the ~/.ssh/config file, I saw this at the bottom:

    Host *
    IdentitiesOnly yes
    

    Then I add this above:

    Host 12gpu
    HostName 192.168.20.160
    User lerner
    IdentityFile ~/.ssh/12gpu_server
    

    I can just log in by entering ssh 12gpu.

    Then you can add multiple ssh keys using your favorite names, and you only need to add the settings like the above four lines to the config file.

    Host is the name you'd like to enter when you connect to the server later; the HostName is the server's ip or domain like github.com; User is the user name you log in the server like the user name or git for github or gitlab; and the IdentityFile is the file where you store the key you have generated.

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

    As explained in Cloning a Git repo from VSTS over SSH asks a password! Unexpected

    The problem may be because of public key authentication failing, so it then asks for mycompany account's password.

    This would not happen if the public key authentication succeeded.

    So you might check id_rsa.pub and even create a new one.

    0 讨论(0)
提交回复
热议问题