It’s been a while since I configured my development computer terminal. I almost forgot how long it takes to go through all the little details and configurations to make it work how I like.

My GitHub personal access token (PAT) expired, which caused a problem when I tried to commit my local changes to the repo. I completely forgot how to renew it. A quick search in Google didn’t provide the exact answer, so I wrote this blog post instead.

The steps below will help you update your GitHub PAT quickly, so let’s dive in.

I’m using Ubuntu 22.04 on my Windows WSL2 terminal. But you can follow along regardless of your choice of terminal or OS. Here’s what I had to do to configure my Ubuntu terminal with my GitHub personal access token. You can use the following steps if you find yourself in the same situation.

  1. You need to generate a personal access token in your GitHub account settings under “Developer settings” > “Personal access tokens”. Select the appropriate scopes for the token based on what you need to do with it. Copy the newly generated token somewhere to reuse it on a different terminal if required.

  2. Open a terminal window in WSL2 and run the following command to create a new file called .netrc in your home directory.

I skipped this part since I already had a file.

touch ~/.netrc
  1. Run the following command to open the .netrc file in a text editor of your choice. I used Nano.
nano ~/.netrc
  1. Add the following lines to the file, replacing “your_username” with your GitHub username and “your_PAT_token” with your personal access token:

I only replaced the expired token.

login <your_GitHub_username_or_email>
password <your_PAT_token>
  1. When done with editing, save the file and exit the text editor.

  2. Run the following command to set the permissions on the .netrc file.

I skipped this part, but you must do it for the newly created file.

chmod 600 ~/.netrc

This will ensure that only you can read and write to the file.

  1. Test your configuration by running a git command that requires authentication, such as git push. If everything is set up correctly, you should be able to push changes to GitHub without being prompted for your username and password.

Note that storing your personal access token in a file on your local machine can be a security risk, especially if someone gains access to your device. Keep your token secure, and don’t share it with anyone. If you suspect your token has been compromised, revoke it immediately and generate a new one. And after that, remember to update the file mentioned above.