Skip to content

Instantly share code, notes, and snippets.

@vheidari
Last active July 12, 2022 10:24
Show Gist options
  • Save vheidari/0588498f662c603cf20dbdee6763971e to your computer and use it in GitHub Desktop.
Save vheidari/0588498f662c603cf20dbdee6763971e to your computer and use it in GitHub Desktop.
Github - Creating a personal access token and add token authentication to github

Github Added token authentication requirements for Git operations in july 2021

Following instruction help us to generating ssh token and add it to github then working with ssh rather than https.

For more information plase read this blog post : MoreInfo


Purpose :

  1. Generating a new key with ssh-keygen
  2. Adding pair private key to ssh-agent with ssh-add
  3. Adding pair public key to github
  4. Changing local repo remote address from https to ssh type

  1. Generating a new key with ssh-keygen

    • $ ssh-keygen -t ed25519 -C "your_email@example.com"
    • or
    • ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    • note : MoreInfo
  2. Adding pair private key to ssh-agent with ssh-add

    • ssh-add ~/.ssh/id_ed25519
    • note: it adding your private key to ssh-agent that we create in section 1
    • note: MoreInfo
  3. Adding pair public key to github

    • inside your github account following below path
    • Settings > SSH and GPG keys > New SSH key [button] > Title [input:text] > Past id_ed25519.pub content in to > key [textarea]
    • note: to copy id_ed25519.pub content : cat ~/.ssh/id_ed25519.pub then copy and passt in to key [textarea]
    • note: MoreInfo
  4. Changing local repo remote address from https to ssh type

    • inside local repo type git remote -v, this command display remote url that sets for this repo
    • we must change theas url from https remote :
    • > origin https://github.com/USERNAME/REPOSITORY.git (fetch)
    • > origin https://github.com/USERNAME/REPOSITORY.git (push)
    • to
    • > origin git@github.com:USERNAME/REPOSITORY.git (fetch)
    • > origin git@github.com:USERNAME/REPOSITORY.git (push)
    • to change to ssh mode type :
    • git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
    • note : MoreInfo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment