每次在Cygwin都会重置`ssh-add`

时间:2017-10-08 02:59:38

标签: git github ssh cygwin

我在Windows 10上使用cygwin终端。但是我遇到了git via ssh的问题。虽然Git Bash终端每次都有效,但cygwin每次都需要ssh-add。我的cygwin发生了什么?

$ which git
/cygdrive/c/Program Files/Git/cmd/git
$ ssh-add -l
Could not open a connection to your authentication agent.
$ eval `ssh-agent`
Agent pid 13900
$ ssh-add -l
The agent has no identities.
$ ssh -vT git@github.com
OpenSSH_7.5p1, OpenSSL 1.0.2k  26 Jan 2017
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /cygdrive/c/Users/jef/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /cygdrive/c/Users/jef/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /cygdrive/c/Users/jef/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
Enter passphrase for key '/cygdrive/c/Users/jef/.ssh/id_rsa':
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi jojef! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2664, received 1848 bytes, in 0.1 seconds
Bytes per second: sent 35785.4, received 24824.1
debug1: Exit status 1

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /cygdrive/c/Users/jef/.ssh/id_rsa:
Identity added: /cygdrive/c/Users/jef/.ssh/id_rsa (/cygdrive/c/Users/jef/.ssh/id_rsa)
$ git pull
Already up-to-date.

Restart cygwin terminal

$ git pull
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我发现Windows命令提示符正常工作。

C:\Users\jef\work\movie_dialog>git pull
Enter passphrase for key '/c/Users/jef/.ssh/id_rsa':
Already up-to-date.
C:\Users\jef\work\movie_dialog>where git
C:\Program Files\Git\cmd\git.exe

更新

我引用了VonC的链接,然后创建了~/.bash_profile,而不是bashrc。我不确定.bashrc是不行的。然后,我可以拉!每次登录Windows时,密码短语只需要一次。 Auto-launching ssh-agent on Git for Windows

1 个答案:

答案 0 :(得分:1)

如果您有set your .bash_profile on Cygwin,它会在每次新的Cygwin会话中询问您的密码,并且您的git pull将会成功。

在Windows上,显然,您每次都要输入密码,但是可以使用Windows git bash中的similar ~/.bashrc来避免使用密码。

在我mentioned before时,git很可能是different between Cygwin and Git for Windows

  

创建了~/.bash_profile,而不是bashrc。我不确定.bashrc是否有效。然后,我可以拉!

作为mentioned here.bashrc仅由互动和非登录的shell读取。但是打开cygwin会话可能会被视为&#34;登录&#34;,这意味着只读取.bash_profile
这就是为什么大多数人最终告诉他们.bash_profile还要阅读.bashrc之类的内容:

[[ -r ~/.bashrc ]] && . ~/.bashrc