Omarchy

How-To: Sign In the GitHub CLI With an Expiring, Fine-Grained Token on Omarchy or Any Linux Box

Leave a comment

Omarchy’s new Setup > Git flow makes GitHub sign-in a one-paste job, but it may default your token to never expire. Here’s how I do it by hand with a token that has an expiration date and only the access it needs. This works on any Linux box with gh installed.

1. Create the token

In GitHub, go to Settings > Developer settings > Personal access tokens > Fine-grained tokens > Generate new token. Give it a name that says which machine it’s for, set an expiration (I use 90 days), choose only the repos it needs, and give it the smallest permissions that work. Contents read/write is enough for push and pull.

2. Hand it to gh without leaving it in your shell history

read -rs GH_PAT && printf '%s' "$GH_PAT" | gh auth login --with-token --git-protocol https; unset GH_PAT

read -rs takes the paste silently, so it’s never echoed or saved to history.

3. Let git use it

gh auth setup-git

4. Check what you’ve got

gh auth status

This shows the account, how the token is stored and the git protocol. Then try a git fetch in one of your repos to confirm.

5. When it expires, or you retire the machine

gh auth logout --hostname github.com

Then delete the token on GitHub’s token page. Make a new one when you need it.

An expiring, narrow token is a little more hassle every few months. That’s a small price compared with an infostealer finding a never-expiring token with access to every repo you own.

God Bless, and Happy hacking!

References & Further Reading

Subscribe (RSS) Follow How-Tos via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.