0
votes

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?

1
This isn't about a "permanent connection with GitHub", but rather a way to have your ssh-agent run persistently. This will depend on your operating system. Please tell us what OS you are using, and which version.Chris
@Chris thanks. I am using CentOS 6.7Brick Yang
Using a graphical environment like Gnome or KDE, or command-line only?Chris
Do you have a passphrase on your SSH key (i.e. when you run ssh-add do you have to type a passphrase in)?Chris
@Chris no. I didn't set passBrick Yang

1 Answers

1
votes

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.