将 RStudio 项目切换为 SSH 身份验证

Switching RStudio project to SSH authentication

好吧,我被难住了。在过去的几个月里,我偶尔会收到来自 GitHub 的严厉消息,警告我我使用密码身份验证提交了我的 R 程序包,这将会消失。美好的。所以我很想换;但是...

我查看了各种帮助文件。我已经让 R 生成一个 RSA 密钥。我已将该密钥复制到我的 GitHub 帐户。我有 运行 ssh-add。在这一切之后,我推送了一个更新,发现我在 GitHub 上的 SSH 密钥信息仍然说它从未被使用过。

我似乎找到了一些有用的东西 。事实上,我验证了我的远程来源显示为 https://github.com/rvlenth.git,这表明它仍然设置为密码验证。所以我按照那里的建议做了删除那个起源。它建议寻找可以为我提供新 link 的内容(如小图所示),但我无法在我的存储库中找到它。看起来应该是git@github.com:rvlenth/emmeans,所以,我像傻子一样运行git remote add origin git@github.com:rvlenth/emmeans.

它似乎接受了,但现在我的 RStudio 界面中的下拉按钮和按钮是灰色的。我试图恢复到 https 设置,但仍然是灰色的。

我该怎么做才能让它发挥作用?我感到被胁迫,因为如果我不知道该怎么做,GitHub 会关闭我。

更新

好的,我找到了绿色按钮并复制了它为 SSH 身份验证提供的 URL。我还创建了一个新密钥,在此过程中输入我的 GitHub 密码,并将 public 密钥复制到 GitHub。我收到一封来自 GitHub 的电子邮件,确认了这一点。它仍然失败。事实上,我只是尝试创建一个新项目,但它甚至无法工作:

>>> C:/Program Files/Git/bin/git.exe clone --progress git@github.com:rvlenth/emmeans.git emmeans
Cloning into 'emmeans'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

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

更新 2

这是我跟进@torek 的建议后得到的结果

$ ssh -Tvvv git@github.com
OpenSSH_8.4p1, OpenSSL 1.1.1i  8 Dec 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/rlenth/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/rlenth/.ssh/known_hosts2'
debug2: resolving "github.com" port 22
debug2: ssh_connect_direct
debug1: Connecting to github.com [140.82.112.4] port 22.
debug1: connect to address 140.82.112.4 port 22: Connection timed out
ssh: connect to host github.com port 22: Connection timed out

看来我有一个相当新的 ssh 版本(显然是因为重新安装了最新版本的 git

早些时候,我做了:

$ ls -l ~/.ssh
total 5
-rw-r--r-- 1 rlenth 197121 1766 Mar  3 16:05 id_rsa
-rw-r--r-- 1 rlenth 197121  400 Mar  3 16:05 id_rsa.pub

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /c/Users/rlenth/.ssh/id_rsa:
Identity added: /c/Users/rlenth/.ssh/id_rsa (/c/Users/rlenth/.ssh/id_rsa)

... 然后我输入了我的 GitHib 帐户的密码。看起来我的主目录已正确解析。我需要创建一个 known_hosts 文件还是什么?

更新 3

自更新 2 以来,我已经完成了:

尽管进行了所有这些更改,但我在执行 ssh -Tvvv git@github.com 时仍然会超时。所以我也尝试了(没有运气测试任何这些)

有没有人成功地设置了 Windows 的 SSH 身份验证?我真的需要你的帮助!

更新 4

我放弃了让 SSH 工作。相反,我按照 GitHub 的说明创建个人访问令牌。到目前为止,这似乎有效。要么,要么它仍在使用我的密码,我会收到另一封指责它的电子邮件。时间会证明一切——但我至少已经备份并且 运行ning.

更新n

更改路由器中的防火墙设置(允许点对点应用程序)后,我现在可以通过 SSH 进行身份验证。最后。有兴趣的朋友可以看看,这里提到的路由器是 Mediacom 提供的路由器:Technicolor TC8305C。

ssh: connect to host github.com port 22: Connection timed out

只要您看到此错误,再多的私人 key/passphrase 也无济于事。 SSH 甚至没有进入身份验证阶段。

I also created a new key, typing-in my GitHub password in the process

当您创建新密钥时,您不必输入密码(起初我不会为了测试 SSH)。
如果您确实输入了密码(这将通过加密来保护您的私钥),则它不必是您的 GitHub 密码(实际上,最好不要输入密码:不要重复使用密码)

OP Russ Lenth confirms in 防火墙问题:

I logged-on to my router and changed a firewall setting to not block peer-to-peer applications.
Now I can connect via SSH.