Easily access your Github repositories using OAuth tokens

As a developer, on your own machine, you access your code repositories on Github using your credentials, but on a production host one should not use his personal account's password or SSH keys.

But in reality, for productivity reasons or cases where we want to do continuous deployment, we may need to access our github repositories from a server host.

There are several options to solve the problem, but one that was easy for me is the "Personal access tokens" solution, which can be used instead of a password for Git over HTTPS on Github.

To create an access token for each server you need to deploy code to:

  1. Go to your Github settings page, and click on the Personal access tokens link.

  2. Click on "Generate new token", and complete the form by setting the right access scope. For example, you may use the "repo" scope to allow accessing your public and private repositories from the server, which means you are giving read and write access.

  3. When ready, click on the "Generate" button, and your token is generated. Copy it in a safe place, as you would with a password.

After this small procedure, now on your server, you are able to clone one of your repositories by providing the token instead of the password, when asked for the account username and password.

$ git clone https://github.com/your_username/your_code_repo.git
Username: your_username
Password: your_token

I have been using this approach for my current code deployments on both PythonAnywhere and Azure and it helps for my productivity.

Note that, as for user accounts, tokens can be deleted whenever you want. For security reasons, it is recommended to regularly check how and when they are used, with the status information provided in the Github "Personal access tokens" interface, and to delete any token that you may find is no more in use.

comments powered by Disqus

Need help for your project?

Our team can contribute to your project, working on a specific task, or doing all the coding based on your specifications, using Python, a web framework such as Django or a CMS.