即使存在于ssh-agent中,Git也要求SSH密码

时间:2017-11-07 10:59:57

标签: git ssh ssh-keys ssh-agent

我每天都在我的Mac上使用带有ssh-agent的git,它运行完美。但是,在我的远程开发服务器上,我应该错过一些东西,因为在进行远程git操作时我无法绕过SSH密码的提示

设置

  1. 密钥列在ssh-agent中: ssh-add -L

    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCktk2+zRYGy0RdM6HJ8JFVPjiNknK7iN8ohdCGSX9fPQ.... 
    /home/user/.ssh/id_rsa.from_user@server_to_git@bitbucket
    
  2. 密钥与~/.ssh/config中的bitbucket相关联:

    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. 环境变量export | grep SSH_A

    SSH_AGENT_PID=30294
    SSH_AUTH_SOCK=/tmp/ssh-IS3rVQtFwDxF/agent.30292
    
  4. 代理正在运行ps -e | grep -q ssh-agent && echo "SSH Agent is running"返回

    SSH Agent is running
    
  5. 权限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. 我的"硬化" /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
    
  7. 然而

    1. 正在运行git clone bitbucket:team/project.git返回

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

      1. 结果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':
        
      2. 任何提示?

1 个答案:

答案 0 :(得分:1)

我刚刚发现IdentitiesOnly需要将公钥存在于本地计算机上才能工作。