E Tech.

Use ssh for GitHub and set GitBash options

Introduction

I don't want to forget how to set up initial settings for GitHub ssh and GitBash. This is memo.

Use ssh for Github on Windows

There are official documents. My way is a little different from these documents.

There are three steps:
1.Generate ssh key pair
2.Register public key to GitHub
3.Register private key to ssh-agent

1. Generate key pair

First, generating ssh key.

ssh-keygen -t ed25519 -C "your_email@example.com"

Then, GitBash asks you file name to save ssh key. If you already have ssh-key pair that has the same name, you should change the file name or folder.

> Enter file in which to save the key (/c/Users/YOU/.ssh/id_ALGORITHM):[Press enter]

After that, it needs to type a passphrase. To use no passphrase, just type enter.

 Enter passphrase (empty for no passphrase): [Type a passphrase]
 Enter same passphrase again: [Type passphrase again]

Now, you get ssh key pair.

2. Register public key

To register a public key to your GitHub account, please follow these instructions(cited from official documents):

1. Copy the SSH public key to your clipboard.
2. In the upper-right corner of any page on GitHub, click your profile photo, then click Settings.
3. In the "Access" section of the sidebar, click SSH and GPG keys.
4. Click New SSH key or Add SSH key.
5. In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal laptop, you might call this key "Personal laptop".
6. Select the type of key, either authentication or signing. For more information about commit signing, see About commit signature verification.
7. In the "Key" field, paste your public key.
8. Click Add SSH key.
9. If prompted, confirm access to your account on GitHub. For more information, see Sudo mode.

3. Register private key

Launch GitBash and run this command:

eval `ssh-agent` 

If you run only ssh-agent, it outputs some environmental variables. The eval immediately set those variables and run ssh-agent.

Then, add ssh private key:

ssh-add "C:\Users\username\.ssh\id_ed25519"

You can clone now.

git clone git@github.com:[what you want]

Set Gitbash options

Edit .bashrc file

At this time, you need to run ssh command every time you launch GitBash. So, edit .bashrc file.
If there is no .bashrc file on your home directory, create it and paste this:

#start ssh-agent
eval `ssh-agent`

#add ssh-key
ssh-add "C:\Users\username\.ssh\id_ed25519"

GitBash runs automatically ssh command as it starts.

Change GitBash config

To use right click as copy and paste in GitBash:
1.Click right button of mouse on the top of GitBash window and choose options
2.See Mouse tab and mark paste on Right mouse button

Reference

Why eval the output of ssh-agent?
ssh-agent Command Line Options
How do I escape a backtick ` within in-line code in Markdown?