DEV Community

Cover image for Setting up your Github workflow with SSH
ritik
ritik

Posted on

Setting up your Github workflow with SSH

As you already know that Github has removed the password authentication support on August 13 2021. They have forced their user to use Personal Access Token instead of password.
But storing and managing access token is very difficult task.
No matter how hard you try to store it. One day you end up creating another one and this cycle never stop.

We don't want to copy paste the long access token just for simple task of pushing our
code to Github. For ease of our task we are going to ssh instead of https.

But first you have to add a ssh key to your Github account but first we to generate one.

Generating SSH key

  • Open up your favorite terminal and type in
$ ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

here replace your_email@example.com with email which is registered on your github account.

  • You will prompted for default file location of key. Just hit enter.
> Enter a file in which to save the key (/home/you/.ssh/algorithm): [Press enter]
Enter fullscreen mode Exit fullscreen mode
  • You will get prompted of passphrase , you can set empty passphrase and just hit enter.

Once thats done you will get your key fingerprint but don't copy it yet because that will be stripped down version of key.

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/ritik/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ritik/.ssh/id_ed25519
Your public key has been saved in /home/ritik/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode
  • In above result select the key file path , in my case it is /home/ritik/.ssh/id_ed25519.pub.

  • run below command.

$ cat /home/ritik/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode
  • Then you find your original key
$ cat /home/ritik/.ssh/id_ed25519.pub
ssh-ed25519 AAAAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxK8475 dwi.ritik20@gmail.com
Enter fullscreen mode Exit fullscreen mode
  • copy all the text except email part. Your key will look something like this. ssh-ed25519 AAAAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxK8475

Registering SSH key on Github

  • Go to your Github setting -> SSH and PGP section.
  • Click on New SSH Key.
  • Give a name to your key.
  • Paste key in shown box.
  • After that save your key.

You have succesfully add ssh key in your Github Acccunt.

Changing remote origin url to ssh

If you have a existing repository which origin url is set on https, you can easily change it to ssh.

  • Find your repository on github and click Code button.
  • And select ssh and copy the text.
  • Text will look something like below text.
git@github.com:your_user_name/your_repo.git
Enter fullscreen mode Exit fullscreen mode
  • Now open your local repository into terminal.
  • Set remote url to ssh
$ git remote set-url origin git@github.com:your_user_name/your_repo.git
Enter fullscreen mode Exit fullscreen mode
  • here origin is your alias of remote url. It should be your alias of remote url in my case i have set it to "origin".

Now you can easily push your code on Github without worrying about access token.

Top comments (2)

Collapse
 
kush__vaibhav profile image
Vaibhav

Book marked it
Great 👏

Collapse
 
akashkumar0 profile image
Akash Kumar

Thanks for this bro