git - 每次在Cygwin重置`ssh-add`

标签 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

最佳答案

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

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

正如我mentioned before一样,git很可能是different between Cygwin and Git for Windows

created ~/.bash_profile, not bashrc. I am not sure .bashrc didn't work. Then, I can pull!



mentioned here一样:.bashrc仅由交互式和非登录 shell 程序读取。但是,打开cygwin session 可能会被视为“登录”,这意味着仅读取.bash_profile
这就是为什么大多数人最终告诉自己的.bash_profile也读取.bashrc的原因,例如:
[[ -r ~/.bashrc ]] && . ~/.bashrc

关于git - 每次在Cygwin重置`ssh-add`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46627127/

相关文章:

ios - 为什么 .pbxproj 文件在版本控制系统中被视为二进制文件?

git - 上传本地仓库到 github.com

java - 将构建和提交哈希添加到 list

Android Studio 崩溃现在无法推送到 GitHub

git - 包含敏感数据的私有(private)和公共(public) Git 存储库

linux - Rhel 中的每个命令都会返回错误

windows - git - 强制 lf 行结尾不捕获二进制文件

java - 如何使用 Eclipse 从 Github 运行下载的嵌套演示 Android 项目?

linux - Perl 系统返回代码 65280 并成功

ssl - 如果我在服务器上没有 SSL 证书,使用 SSH (PuTTy) 是否安全?