You are not logged in.

#1 2021-10-13 23:39:00

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

[SOLVED] Use GitHub SSH key without entering username and password

I setup my key following these instructions and setup a passphrase for the key. GitHub only provides instructions for what I seek for Mac and Windows.

How do I setup my system so that GitHub doesn't request my password for every action?

Last edited by ThinkPad (2022-02-16 21:15:32)

Offline

#2 2021-10-14 03:12:30

YodaEmbedding
Member
Registered: 2021-10-13
Posts: 3

Re: [SOLVED] Use GitHub SSH key without entering username and password

1. Generate SSH public/private key pair for your current PC. Name it something useful like username@PC-Name. Run:

ssh-keygen -C "$(whoami)@$(uname -n)-$(date -I)"

2. Tell Github your SSH public key, usually located in

~/.ssh/id_rsa.pub

3. Change your .gitconfig so that git automatically translates non-SSH requests to SSH ones. https://stackoverflow.com/a/36500841/365102 suggests:

[url "ssh://git@github.com/"]
  insteadOf = https://github.com/

Here's my personal .gitconfig, if you're interested. Apparently, I was using the following, which also works:

[url "git@github.com:"]
    insteadOf = https://github.com

Fun fact: you can also auto-sign your commits using a GPG key.

Last edited by YodaEmbedding (2021-10-14 03:25:29)

Offline

#3 2022-02-16 20:09:16

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

Re: [SOLVED] Use GitHub SSH key without entering username and password

Thank you for taking the time to write this up! While this was very helpful, it was not the solution for me. I'd also recommend against using RSA.

What worked for me was properly configuring and starting my ssh-agent (see Step 4). For one I was including a trailing `&` in my ~/.xinitrc command and two I did not configure the agent to cache my password.

Inspired by and based on the simplified instructions posted by @YodaEmbedding, and to properly document this full process on an Arch channel, I post the following:

1. Generate SSH public/private key pair for your current PC. Name it something useful like "username@hostname-todays-date":

ssh-keygen -t ed25519 -C "$(whoami)@$(hostname)-$(date -I)"

2. Tell Github your SSH public key:

cat ~/.ssh/id_ed25519.pub | xclip

3. Add your SSH key to the ssh-agent:

$ eval `ssh-agent` 
$ ssh-add ~/.ssh/id_ed25519

4. Configure your ssh-agent and start it for every X session (this is the most important step to make these settings persist and avoid entering your password repeatedly).

Add this to ~/.ssh/config (thanks to the tip in this section):

AddKeysToAgent yes

Add this to ~/.xinitrc (thanks to the note in this section):

eval `ssh-agent`

Note the lack of an `&`!

Now you will only have to enter your password the first time in any session, and it will be cached for the remainder of the session.

This is all I needed; I found that adding the line in Step 5 to my config made no difference. Maybe it's because I clone with the SSH url (git@github.com). In any case, this article might help those who have already cloned with HTTP, and the step is repeated below for convenience.

5. Change your .gitconfig so that git automatically translates non-SSH requests to SSH ones. This SO post suggests:

[url "ssh://git@github.com/"]
  insteadOf = https://github.com/

OR

git config --global url.ssh://git@github.com/.insteadOf https://github.com/

Marking as solved.

Last edited by ThinkPad (2023-02-10 05:12:03)

Offline

Board footer

Powered by FluxBB