Git ask for SSH passphrase even if present in ssh-agent

痴心易碎 提交于 2021-01-27 21:23:18

问题


I use git with ssh-agent on a daily basis on my Mac and it works flawlessly. However, on my remote development server, I should miss something because I can't bypass the prompt for the SSH password when doing remote git operations.

Setup

  1. The key is listed in the ssh-agent: ssh-add -L:

    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCktk2+zRYGy0RdM6HJ8JFVPjiNknK7iN8ohdCGSX9fPQ.... 
    /home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket
    
  2. The key is associated to bitbucket in ~/.ssh/config:

    Host *
        IdentitiesOnly yes
        ServerAliveInterval 600
        ServerAliveCountMax 5
        TCPKeepAlive no
        IdentitiesOnly yes
    
    
    Host bitbucket bitbucket.org
       User git
       Hostname bitbucket.org
       KexAlgorithms diffie-hellman-group1-sha1
       Identityfile  /home/user/.ssh/id_rsa.user@server_to_git@bitbucket
    
  3. Environment variables export | grep SSH_A:

    SSH_AGENT_PID=30294
    SSH_AUTH_SOCK=/tmp/ssh-IS3rVQtFwDxF/agent.30292
    
  4. Agent is running ps -e | grep -q ssh-agent && echo "SSH Agent is running" returns

    SSH Agent is running
    
  5. Permissions ls -al ~/.ssh:

    total 48K
    drwx------  2 user user 4,0K oct.  30 18:22 .
    drwxr-xr-x 18 user user 4,0K nov.   7 11:52 ..
    -rw-------  1 user user  431 mai   10  2016 authorized_keys
    lrwxrwxrwx  1 user user   62 oct.  30 16:50 config -> /home/user/.dotfiles/machine-specific/base/ssh/config
    -rw-------  1 user user  134 mars  26  2017 environment-
    -rw-------  1 user user  137 nov.   7 11:22 environment-server
    -rw-------  1 user user 1,8K mai   16 13:38 id_rsa.from_user@server_to_git@bitbucket
    -rw-r--r--  1 user user 2,6K oct.  30 11:02 known_hosts
    
  6. My "hardened" /etc/ssh/ssh_config:

    AddressFamily inet
    BatchMode no
    CheckHostIP yes
    Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
    Compression yes
    ForwardAgent no
    ForwardX11 no
    GSSAPIAuthentication no
    GSSAPIDelegateCredentials no
    Host *
        HashKnownHosts yes
        SendEnv LANG LC_*
    HostbasedAuthentication no
    KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
    MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
    PasswordAuthentication no
    PermitLocalCommand no
    Port 22
    Protocol 2
    RSAAuthentication yes
    RhostsRSAAuthentication no
    StrictHostKeyChecking ask
    Tunnel no
    

However

  1. Running git clone bitbucket:team/project.git returns

    Enter passphrase for key '/home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket':
    

Debug

  1. Result ssh -v bitbucket:

    OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
    debug1: Reading configuration data /home/user/.ssh/config
    debug1: /home/user/.ssh/config line 1: Applying options for *
    debug1: /home/user/.ssh/config line 10: Applying options for bitbucket
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 12: Applying options for *
    debug1: Hostname has changed; re-reading configuration
    debug1: Reading configuration data /home/user/.ssh/config
    debug1: /home/user/.ssh/config line 1: Applying options for *
    debug1: /home/user/.ssh/config line 10: Applying options for bitbucket.org
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 12: Applying options for *
    debug1: Connecting to bitbucket.org [104.192.143.2] port 22.
    debug1: Connection established.
    debug1: identity file /home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket type -1
    debug1: identity file /home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket-cert type -1
    debug1: identity file /home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket type -1
    debug1: identity file /home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
    debug1: Remote protocol version 2.0, remote software version conker_1.0.314-df0526e app-132
    debug1: no match: conker_1.0.314-df0526e app-132
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: server->client aes128-gcm@openssh.com <implicit> none
    debug1: kex: client->server aes128-gcm@openssh.com <implicit> none
    debug1: sending SSH2_MSG_KEXDH_INIT
    debug1: expecting SSH2_MSG_KEXDH_REPLY
    debug1: Server host key: RSA 97:8c:hidden:hidden:....
    debug1: Host 'bitbucket.org' is known and matches the RSA host key.
    debug1: Found key in /home/user/.ssh/known_hosts:1
    debug1: ssh_rsa_verify: signature correct
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Trying private key: /home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket
    debug1: key_parse_private2: missing begin marker
    debug1: key_parse_private_pem: PEM_read_PrivateKey failed
    debug1: read PEM private key done: type <unknown>
    Enter passphrase for key '/home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket':
    

Any hint ?


回答1:


I just discovered that IdentitiesOnly needs the public key to be present on the local machine to works.



来源:https://stackoverflow.com/questions/47156229/git-ask-for-ssh-passphrase-even-if-present-in-ssh-agent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!