How to create access token to push files to github or gitlab
What is an access token ?
According to wikipedia :
In computer systems, an access token contains the security credentials for a login session and identifies the user, the user’s groups, the user’s privileges, and, in some cases, a particular application.
So basically, it’s a kind of password system but generalized to an whole entity. It helps applications to create sessions by using third party authentication credentials, for example.
What is git ?
Git is a solid versioning system mainly used in IT, in order to handle files history and applications deployment. There are many related platforms in the industry, but I will only talk about Github and Gitlab here.
Motivation
If you are new to git, this article is made for you. Since github stopped using password-based SSH authentication, it may be difficult for newbies to connect to their github account from their PC. Let’s start.
Prerequisites
This article assumes that you :
- have installed git CLI
- already have created an empty repository in your github/gitlab account
- have a local folder that you want to push to your remote repository.
Steps
1. Open your git CLI to generate your SSH keys
No matter what folder you are in, just write down this code in your git CLI to generate a brand new access token :
With changing the mail address to yours, of course.
You will afterwards have all the messages below.
For the next lines, all you need to do is to press enter.
Note : In this example, I specified the name of my generated ssh keys to newssh
because I already have id_ed25519
file in store. In your case, you don’t have to rename it.
2. Verify your generated SSH keys
Check out the /C/Users/yourusername/.ssh/
folder to make sure that your ssh keys are properly generated. You should have generated two files : id_ed25519
and id_ed25519.pub
.
3. Add the access token to your local machine
Before next step, you need to make sure that ssh-agent service in your local machine is on. To do so, execute the following line code in your git CLI :
This should give you a PID number, as follows :
And now add it to your machine with the following script :
Note : in my case, I replaced id_ed25519
with my file name, which is newssh
.
Now let’s share your public token.
4. Store access token remotely
In github
- Go to
- Click on then on
- Add a relevant title to your SSH key, and paste the whole content of your
id_ed25519.pub
local file. - Save it by clicking on Add SSH key.
You are ready to push files !
In gitlab
- Go to , then
- Add a relevant title to your SSH key, and paste the whole content of your
id_ed25519.pub
local file. - Additionally, you can add an expiration date. In my case, I will leave it blank.
- Save it by clicking on Add key.
You are ready to push files !
5. Test your SSH keys
You can test your SSH keys by pushing your local files to your remote repository. To do so, open your git CLI in the folder that you want to push, and execute these lines :
And you should have the following results :
And next time you will commit local files, just use git push
without defining the upstream branch.
That’s all folks !