1. Check for existing ssh key
  2. Generate ssh key (if no key)
  3. Adding ssh private key to ssh-agent (optional)
    1. Run ssh-agent
    2. Add ssh private key to the running agent
  4. Adding ssh public key to GitHub account
  5. (Appndiex)
    1. Change a exsiting project authorization from HTTPS to SSH

Check for existing ssh key

ls -al ~/.ssh

Generate ssh key (if no key)

ssh-keygen -t ed25519 -C "luchongkai96@gmail.com"

Replace the email address with yours

Adding ssh private key to ssh-agent (optional)

So you only need type the passwd once in every session.

Run ssh-agent

eval "$(ssh-agent -s)"

Add ssh private key to the running agent

ssh-add ~/.ssh/id_ed25519

Adding ssh public key to GitHub account

  • Copy the SSH public key to your clipboard.
    cat ~/.ssh/id_ed25519.pub
    
  • In the upper-right corner of any page, click your profile photo, then click Settings. image

  • In the “Access” section of the sidebar, click SSH and GPG keys.

  • Click New SSH key or Add SSH key. image

  • In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key “Personal MacBook Air”.
  • Paste your key into the “Key” field. image

(Appndiex)

Change a exsiting project authorization from HTTPS to SSH

git remote rm origin
git remote add origin git@github.com:user/repo.git # change to your ssh .git
git fetch origin
git push --set-upstream origin master