Skip to content

Always having to enter passphrase for ssh key for git

So I've started using git and github recently, and I got tired of constantly entering my credentials, so I attempted to set up an SSH key authentication using these instructions.

Now, it seems to work for the most part, but I seem to have to enter my SSH passphrase quite often. Anytime I open a terminal and attempt to access it, it prompts me (sometimes as soon as I navigate to the directory with a repo).

I'd like to be able to just login (I use lightdm and herbstluftwm if this makes any difference) and have it work. Any advice as to what's going on or what I need to look at? Thanks in advance.

Also, is there any better place I should post this, should I not find any answers here?

1 points7 comments
Open on Reddit
About this post
Posted
Archived
Score
1 · 100% up
Kind
Text
ID
2vl385

Author

46
posts
64
comments
11
media
View profile

9 comments

Everyone here is recommending an ssh agent (and that will probably work), but here is an alternative that is imo simpler: SSH ControlMaster. What the following config options will do is actually cache/keep open all SSH connections for however long you specify (Google it for a better/more detailed explanation).

# add this to ~/.ssh/config
Host *
    ControlMaster Auto
    ControlPath ~/.ssh/cm/%r@%h:%p
    ControlPersist 10m

If you don't want this enabled for all of your ssh connections, change the "*" above to "github.com". Also change the "10m" to however long you think is appropriate. So instead of caching your credentials, this persists the connection. (As a side effect, if you don't push/pull anything for a while you will see a timeout message, but this can be ignored. Simply means that next time you push/pull you will need to login again.)

4 points

As others have suggested, try using an ssh-agent.

Here's an example of what I typically do, I find it works well. I use tmux and have this in my .tmux.conf:

set-option -g update-environment "SSH_CLIENT SSH_CONNECTION"

When I start my terminal, I'll unlock my keys and add them to my agent.

eval $(ssh-agent) && ssh-add ~/.ssh/github.key

Then I start a new tmux session, if I need to close the terminal for any reason, I just detach the tmux session. When I re-attach, my keys are still unlocked.

3 points

I just removed the password from my ssh key since my home is encrypted anyways.

-1 points

Which is fine, if you don't care about your private key sitting on your computer in plain text.

1 points

If you aren't using home encryption, then the rest of your files are sitting there in plaintext too. There's not much reason to double encrypt your ssh key unless you leave your computer on and unattended in public, which is kind of hard to do on a desktop.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.