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

问题描述

我遵循了生成一个ssh密钥,用于从服务器连接到github。



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

 时, 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:54