管理多个 rsa 密钥(git,网络服务器)
managing multiple rsa keys (git, web server)
我正在学习如何使用 git 和 GitHub。当我‘git push origin master’时,它会提示我输入我的 GitHub 用户并通过组合。所以设置 ssh 密钥会让我的生活更轻松、更方便。我使用的指南实际上是一位名叫 Jason Taylor 的老师开设的 udemy 课程。该课程在付费墙后面,所以我不能真正分享具体的视频。我所在的模块建议输入此命令:
$ ssh-keygen -t rsa -C "[$user]@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/gnull/.ssh/id_rsa):
/home/[$user]/.ssh/id_rsa already exists.
Overwrite (y/n)? n
$
Jason Taylor 的 udemy 课程中的大多数其他学生都会按“y”。这很简单。但对我来说,我已经有一个 id_rsa 文件,其中包含用于我的网络服务器的密钥。因此,如果我输入“y”,我将撤销对我的网络服务器的 rsa 访问权限。对不对?
如何保留对我的网络服务器的 ssh 密钥访问并建立与 GitHub 的 ssh 密钥连接?
以下是我的主文件夹中的 .ssh 目录的内容:
$ ls
id_rsa id_rsa.pub known_hosts
$
Enter file in which to save the key (/home/gnull/.ssh/id_rsa):
在这一步中,您可以输入不同的文件来保存您的ssh密钥对。
并且在你的 ~/.ssh/config 中,你可以为每个主机(服务器)指定密钥文件(identifyFile)。
Here 是一个很好的多 SSH 身份教程。
在 Google 中搜索“管理多个 rsa 密钥”时,排名靠前的是 this(1) stack overflow post。正如 @Roman 在他的评论中指出的那样,post 教授如何添加和管理多个 rsa 密钥,这对我来说不是必需的。我在 GitHub 上找到了一份官方文档 (2),它解释说您可以简单地将现有的私钥或 public 密钥(就像我已经为我的网络服务器建立的那样)复制到我的剪贴板,然后只需将其添加到 GitHub。然后根据另一个 GitHub 文档 (3),您可以通过尝试 ssh 到 GitHub 来测试您的 ssh 连接。这是命令:
$ ssh -T git@github.com
当我输入它时,返回了这个:
Hi [$username]! You've successfully authenticated, but GitHub does not provide shell access.
耶!那奏效了。我的密钥设置正确。但我注意到
$ git push origin master
...仍然提示我输入 GitHub 凭据。我好心人在#github FreeNode network on irc 推荐我试试:
$ git remote -v
返回的是:
origin https://github.com/[$username]/[$project-name].git (fetch)
origin https://github.com/[$username]/[$project-name].git (push)
注意到“https://”了吗?这就是问题所在。解决方案:
$ git remote set-url origin git@github.com:[$username]/[$project-name].git
现在,最后,当我调用时,
$ git push origin master
...它会将我的本地更改推送到 GitHub 而不会提示我输入用户名和密码。
(1):
(2): https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
(3): https://help.github.com/articles/testing-your-ssh-connection/
请注意:Whosebug 不允许我 post 超过两个超链接,这就是为什么我非常规地设置了三个超链接的原因。
我正在学习如何使用 git 和 GitHub。当我‘git push origin master’时,它会提示我输入我的 GitHub 用户并通过组合。所以设置 ssh 密钥会让我的生活更轻松、更方便。我使用的指南实际上是一位名叫 Jason Taylor 的老师开设的 udemy 课程。该课程在付费墙后面,所以我不能真正分享具体的视频。我所在的模块建议输入此命令:
$ ssh-keygen -t rsa -C "[$user]@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/gnull/.ssh/id_rsa):
/home/[$user]/.ssh/id_rsa already exists.
Overwrite (y/n)? n
$
Jason Taylor 的 udemy 课程中的大多数其他学生都会按“y”。这很简单。但对我来说,我已经有一个 id_rsa 文件,其中包含用于我的网络服务器的密钥。因此,如果我输入“y”,我将撤销对我的网络服务器的 rsa 访问权限。对不对?
如何保留对我的网络服务器的 ssh 密钥访问并建立与 GitHub 的 ssh 密钥连接?
以下是我的主文件夹中的 .ssh 目录的内容:
$ ls
id_rsa id_rsa.pub known_hosts
$
Enter file in which to save the key (/home/gnull/.ssh/id_rsa):
在这一步中,您可以输入不同的文件来保存您的ssh密钥对。
并且在你的 ~/.ssh/config 中,你可以为每个主机(服务器)指定密钥文件(identifyFile)。
Here 是一个很好的多 SSH 身份教程。
在 Google 中搜索“管理多个 rsa 密钥”时,排名靠前的是 this(1) stack overflow post。正如 @Roman 在他的评论中指出的那样,post 教授如何添加和管理多个 rsa 密钥,这对我来说不是必需的。我在 GitHub 上找到了一份官方文档 (2),它解释说您可以简单地将现有的私钥或 public 密钥(就像我已经为我的网络服务器建立的那样)复制到我的剪贴板,然后只需将其添加到 GitHub。然后根据另一个 GitHub 文档 (3),您可以通过尝试 ssh 到 GitHub 来测试您的 ssh 连接。这是命令:
$ ssh -T git@github.com
当我输入它时,返回了这个:
Hi [$username]! You've successfully authenticated, but GitHub does not provide shell access.
耶!那奏效了。我的密钥设置正确。但我注意到
$ git push origin master
...仍然提示我输入 GitHub 凭据。我好心人在#github FreeNode network on irc 推荐我试试:
$ git remote -v
返回的是:
origin https://github.com/[$username]/[$project-name].git (fetch)
origin https://github.com/[$username]/[$project-name].git (push)
注意到“https://”了吗?这就是问题所在。解决方案:
$ git remote set-url origin git@github.com:[$username]/[$project-name].git
现在,最后,当我调用时,
$ git push origin master
...它会将我的本地更改推送到 GitHub 而不会提示我输入用户名和密码。
(1):
(2): https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
(3): https://help.github.com/articles/testing-your-ssh-connection/
请注意:Whosebug 不允许我 post 超过两个超链接,这就是为什么我非常规地设置了三个超链接的原因。