我如何使用SSH密钥从服务器设置永久连接到github? [英] How could I setup a permanent connection to github from server with SSH key?

查看:235
本文介绍了我如何使用SSH密钥从服务器设置永久连接到github?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了 https://help.github.com/articles/上的指南生成-ssh-keys / 生成一个ssh密钥,用于从服务器连接到github。



问题是如果关闭shell并登录服务器再次,我不得不重复下面的步骤重新连接到github,否则访问将被拒绝:

  eval$(ssh -agent -s)
ssh-add〜/ .ssh / id_rsa

我设置了一个与github的永久连接?<​​/ p>

解决方案

由于您登录到命令行(假定使用SSH)包括 ssh-agent ,在您注销时停止。



在我看来,您最好的选择是让您的CentOS机器每次登录时都为您启动 ssh-agent ,然后手动使用 ssh-add 来添加你的密钥。这可以通过修改你的shell的登录脚本来完成。如果你使用bash,这个文件被称为〜/ .bash_profile 。编辑其中一个文件并添加 eval$(ssh

现在,每次登录 ssh-agent 时, code>应自动启动,并且可以选择运行 ssh-add (因为您使用的是 ssh-add 在默认情况下寻找你不需要传递文件到命令)来添加你的密钥,然后做Git的东西。



听起来像你还想自动添加密钥。这不是我会选择做的事情,因为我喜欢将键添加为明确的,但因为您的SSH密钥上没有密码,所以应该可以添加 ssh-add 添加到我们上面修改过的同一个文件中(当然我们启动代理之后),并自动添加您的密钥。


I followed the guide from https://help.github.com/articles/generating-ssh-keys/ to generate a ssh key used to connect to github from my server.

The problem is if I close the shell and login the server again, I have to repeat below steps to reconnect to github, otherwise the accessing will be denied:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

How can I setup a permanent connection with github?

解决方案

Since you are logging on to the command-line (presumably using SSH) all applications that you run, including ssh-agent, stop when you log out.

In my opinion your best bet is to have your CentOS machine start ssh-agent for you each time you log in, then manually use ssh-add to add your key. This can be done by modifying your shell's login script. If you are using bash, this file is called ~/.bash_profile. If you are using another shell, refer to its documentation and choose an appropriate file.

Edit one of these files and add eval "$(ssh-agent -s)" at the end.

Now, each time you log in ssh-agent should automatically start, and you can optionally run ssh-add (since you are using a file that ssh-add looks for by default you don't need to pass the file to the command) to add your key, then do Git stuff.

It sounds like you want to automate the adding of the key as well. This isn't something that I would choose to do since I like adding keys to be explicit, but because you don't have a passphrase on your SSH key you should be able to add ssh-add to the same file we modified above (after we start the agent, of course) and have your key added automatically.

这篇关于我如何使用SSH密钥从服务器设置永久连接到github?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆