Deprecated Plain User and Password

Viewed 168

I have several projects using plain user name and password in a few git clients.

The problem is that username/password authentication is not supported for GitHub anymore.

What can I change or what is the best option to make them work?

1 Answers

TL;DR

A PAT (personal access token) can be used just like a password to authenticate to GitHub as your user. You can use this both for the GitHub API and in order to interact using git.

SSH allows you to clone/push/pull from/to git repositories using the ssh protocol.

Deploy keys are just like SSH but for a single repository.

OAuth2 can be used for an application to ask for your permission to access GitHub.

Why is it deprecated?

You simply should not use your normal password directly because

  • You would need to save the password in clear text or encrypt it but key the encryption key next to the encrypted password making the encryption useless.
    Anyone with access to your computer (if you get a virus or somebody steals your hard drive or similar) they could just read your GitHub password.
  • You could not differentiate between different applications and would need to use the same password for every application. Any of those applications could steal your GitHub password.
  • You cannot restrict permissions if you give the application your username and password as they have access to your whole account.

What other options do you have?

PAT

The simplest way of migrating from username/password authentication to something else on GitHub is a PAT (personal access token).

You can generate a personal access token under Settings>Developer Settings by clicking on Generate new token. You can then select scopes that define what the token is allowed to be used for.

It is recommended to create a distinct token per application with the least amount of privileges so that you can easily revoke it if it is stolen.

You can just use the token instead of the password in order to interact with GitHub.

SSH

You can also use SSH to read/write from/to a repository.

At first, you will need to generate an SSH key in order to use it.

After that, you can add it in the SSH and GPG keys section of your account settings by clicking on New SSH key.

This process is explained here.

Here, you paste your SSH key.

After setting it up, you can use it to access repositories using SSH without being prompted for username/password.

Deploy keys

If an application is supposed to interact with a specific repository, a deploy key might be a better idea.

Deploy keys are SSH keys that are valid for a single repository only.

In order to use deploy keys, you need to create those at first.

You can configure deploy keys per repository under /settings/keys (https://github.com/<username>/<reponame>/settings/keys). You can then click Add deploy key, select a name for the key and paste the key.

After setting up the deploy key, the application can read from the repository (or write to it if you configure it that way).

OAuth2

Another way of communicating with GitHub is using OAuth2.

The application would redirect you (or open a browser) to GitHub. You sign in to GitHub and authorize the application to whatever it needs to have access to. GitHub then redirects you to the application and it can access whatever you allowed it to access.

Many GitHub applications already support OAuth2 so that is fine.

In order to use OAuth2 for your own application you need to create an OAuth2 application at first. You can do so in Settings>Developer Settings by clicking on Register a new application.

The program can then ask to authorize it so that it has access to the account.

Related