1

ok so I've read numerous posts on this online and none are really clear cut or at least for someone of my skill level. I set up Ubuntu Subsystem on windows and I am trying to set up my github keys so that I don't have to login on each push etc.

If you have simple steps feel free to ignore the rest below just wanted to make sure I provided as much info as to what I tried below.


I tried this method but still can't get it to work - Running SSH Agent when starting Git Bash on Windows

Here are the full steps I took

1) I ran $ ssh-keygen -t rsa -b 4096 -C "my@email.com"

pressed enter on prompt adding the keys to default location wish is /.ssh (on the linux side) on windows located here: C:\Users\MyUserName\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\MyUserName\.ssh

Files added after this step in /.ssh

/.ssh
   id_rsa
   id_rsa.pub

2) Next I modified my .bashrc with nano

$ nano ~/.bashrc

This opened C:\Users\MyUserName\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\MyUserName\.bashrc

I added the following snippet to the end of my existing .bashrc

# Set up ssh-agent
SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initializing new SSH agent..."
    touch $SSH_ENV
    chmod 600 "${SSH_ENV}"
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' >> "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add
}

# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    kill -0 $SSH_AGENT_PID 2>/dev/null || {
        start_agent
    }
else
    start_agent
fi

3) I ran source ~/.bashrc

4) created config file $ touch ~/.ssh/config

5) In config here's what I have and where I think I went wrong maybe.

This is the snippet from the original post referenced above

Host github.com-<YOUR_GITHUB_USERNAME> 
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_work_gmail # path to your private key
AddKeysToAgent yes


Host csexperimental.abc.com
IdentityFile ~/.ssh/id_work_gmail # path to your private key
AddKeysToAgent yes

<More hosts and github configs can be added in similar manner mentioned above>

Here's mine

Host github.com-MyGithubUsername
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
AddKeysToAgent yes

6) Then I added key to agent by running $ ssh-add ~/.ssh/id_rsa

I ran $ ssh github.com-MyGithubUsername to check if everything was ok and got back

The authenticity of host 'github.com (192.XX.XXX.XXX)' can't be established.
RSA key fingerprint is SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
Are you sure you want to continue connecting (yes/no)?

I typed yes and got back

Warning: Permanently added 'github.com,192.XX.XXX.XXX' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi MyUserName! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

Tried pushing a commit after this and was still asked for my log in


I also came across this post and tried my best some of those things but didn't work either so I started from scratch and tried the above

Any help would be GREATLY appreciated :/

  • Sounds like the agent stopped running. Immediately before you push, does `ssh-add -l` show your key? – jhnc Feb 04 '19 at 00:03
  • yes it does ... and smh I changed the remote to use ssh instead of http and that worked. In all the fog of trying so many things that one got by my radar ugh smh lol .. now to start from scratch and identify which steps were needed and which weren't .. from what you saw the steps above .. anything I can leave out or don't need to do or is there a better way or should I just stick with this method ? – Daniel Nunez Feb 04 '19 at 00:05
  • Yes, the remote can't be http :) Steps seem fine. – jhnc Feb 04 '19 at 00:07

1 Answers1

0

The steps are OK, provided you are using an SSH URL:

cd /path/to/my/repo
git remote -v

If it starts with https:

git remote set-url origin github.com-MyGithubUsername:<mylogin>/<myrepo>

Note that the SSH agent is only needed if you have added a passphrase when setting up your private key.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250