Sublime Forum

Caching a Personal Access Token - Authentication

#1

As of last Friday, it seems I am unable to use my github password to authenticate myself, and now have to use a Personal Access Token. This seems counter intuitive to me, because, at least I can remember my own passwords, there is no way I can remember this PAT.

Documentation from Sublime is vague, at best, and basically points to Github’s steps to create a PAT. OK, what do i do with this PAT? Am I expected to use this PAT everytime I do a git action? Can I cache my credentials with Sublime Merge for longer than 7 days? I see documentation on using Git Credentials store or an OS keyring, but specific documentation is lacking or vague, especially for Linux. As popular as Linux is with developers, I’d be surprised if I’m the only one struggling to understand how to cache credentials.

Can anyone suggest a way to cache my github credentials?

As someone with mobility and dexterity issues, convenience and usabilty is way more important to me than security.

1 Like

#2

If this is the case, I’m surprised you’re not using SSH keys. I’ve been using them for years & have only typed my password once (also due to the macOS KeyChain app). There should be plenty of Linux guides to have a similar behavior. (including in the linked github guide, here)

2 Likes

#3

Hi @pdxwebdev503,

If you’d like to continue using HTTPS authentication, you can use the following command to cache the details for an arbitrary amount of time:
git config credential.helper 'cache --timeout=x'

Note that x is the number of seconds you’d like to cache it for. This data is stored in memory, and will be erased when the computer shuts down.

Additionally, it’s worth taking a look at https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git as an alternative method of credential management.

If you’d like to continue using password-based authentication, I’d suggest using SSH has @srbs has already mentioned.

Hope this helps!
- Dylan from Sublime HQ

1 Like

#4

Thanks, I was able to use these links to generate an SSH key. Admittedly, I do not know much about SSH, and what I do know has been tainted because I am a long time Windows user. Very clear and straight forward!

The only confusion I encountered was after I generated the key and added it to my Github, I still had to give Sublime Merge my username and PAT one last time before it “remembered” the ssh key.

EDIT: Nevermind, it seems sublime merge is refusing to acknowledge my keys, and authentication doesn’t persist for more than a few minutes

0 Likes

#5

Dylan,

Thanks. I have created my keys. Verified they work in the terminal, yet Sublime Merge is ignoring this and insists on authenticating with my username and passwo… i mean my extremely long PAT.

Can you provide more info on how to use SSH with merge, please?

0 Likes

#6

I needed to change my local repo url to use an SSH version of URL. That key step seems to be not mentioned anywhere except very briefly here: https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories… wish i knew that 6 hours ago…

0 Likes

#7

Yup, that’s the one. I didn’t even think to mention that requirement. Also note: now that you have an SSH key setup in your GitHub account, the clone popup will default to the SSH URL. If you have more than one machine, I’d recommend setting up SSH on others too.

0 Likes

#8

well the saga continues…

apparently, i keep speaking too soon. I keep thinking I got it but no, I don’t have a viable solution yet .

My hunch is that my SSH key is not being added when I first boot up my machine (I am not prompted for my system password when first logging in.) I am lost on how to fix this.

My last attempt was to add the following to my ~/.ssh/config file

AddKeysToAgent yes

Host github.com
    User git
    IdentityFile ~/.ssh/id_mykeyfile

Not sure exactly what that does… Ref: https://stackoverflow.com/questions/3466626/how-to-permanently-add-a-private-key-with-ssh-add-on-ubuntu

When I use the terminal to do a git action, like git push, I am prompted to authenticate. If I choose default authentication, a browser window opens saying I’m authenticated. After this, sublime merge works. I never am prompted for a password, not my github password nor the private key password.

When I try to use sublime merge immediately (without using the terminal first), the app prompts me for my username and password (which is incorrect since I’m no longer allowed to use my own password and have to use some ridiculous, ,arbitrary string). When I cancel, I get some error message saying the terminal cannot be accessed in order to validate. So does this mean theres a bug in Merge preventing it from using git? Your documentation says Merge is using git, but in this case, its failing.

0 Likes

#9

Hi @pdxwebdev503,

Apologies for the difficulties authenticating with GitHub!

It sounds like Git may still be using HTTPS to authenticate with the remote you’re pushing to.
Typically if a browser window is appearing, it would suggest that Git is using HTTPS / GCM to authenticate.

Could you navigate to the repository on the command line, and run git remote -v.

If you see any remote URLs starting with https, then they will need to be updated to use an SSH URL.

For example https://github.com/sublimehq/Packages.git would need to be updated to git@github.com:sublimehq/Packages.git

This can be done using Sublime Merge as of Build 2059 (shown below):

If you can see SSH URLs already, could you run ssh-add -l via the command line and confirm it displays the details of your newly created ssh key.

  • If it doesn’t display the key details, it would indicate that the ssh key hasn’t been added to the ssh-agent. In that case, these steps should resolve the issue.

  • If the details of the ssh key are displayed, could you confirm that you’ve performed these steps here.

If none of these steps resolve the issue, let me know and I’ll be happy to investigate further!

Kind regards,
- Dylan from Sublime HQ

1 Like

#10

Great! Thank you for your reply. This is the context that I’ve been misunderstanding.

I was able to confirm that my push url still had the https url.

(Earlier, I attempted to change the repo URLs by executing git remote set-url origin git@github.com:username/repo ref. This changed the fetch url, not the push).

I was not able to upgrade my version of Sublime Merge. I believe I have build 2020. I tried a few different ways of trying to upgrading, including uninstall --> reinstall.

I was finally able to update the repo URLs by editing my .git/config file. Now Subl Merge is prompting me for my private key passcode. Yay! everyone wins. thanks again… clearly I need to get better Ubuntu debugging skills :wink:

0 Likes