gitgithubgitea

How to prevent creating private key everytime I want to push on github or gitea


Everytime I want to push something I have to type my username and password(private key) to terminal.

I know there is a way that I can just type git push and it will automatically push all changes to github. How can I fix it?


Solution

  • You shouldn't ever use your private ssh key, I hope this isn't what you are doing and you just mean password on github.

    A way you can push without having to identify yourself goes as following:

    In your terminal: ssh-keygen for ubuntu and Windows. This will make a public and private ssh key and save them in a file(again NEVER use your private key, this should only be present at your computer in 99% of cases.)

    Find the public key (will be in root folder under .ssh/ and a file ending with .pub) the ssh-keygen will specify its location.

    Now that you have your public key copy paste it (the whole content of the file) and head to github. Go to settings -> SSH and GPG keys -> new SSH key -> simply follow the steps it gives you.

    Now just to make sure everything is configured correctly, go to your git repository and clone it using SSH (not HTML which is set as default). And clone it again. It will probably say github is an unknown host and whether you want to add it to known hosts or not (you will get 3 options yes/no/[fingerprint], make sure you type yes).

    Hope this helps, if any questions free feel to contact me