Problem
I am trying to set up GitHub authentication in RStudio on Windows using a Personal Access Token (PAT). When I run RStudio as an administrator, I can successfully set and use the PAT with gitcreds::gitcreds_set()
and perform GitHub operations like cloning repositories. However, when I run RStudio as a non-admin user, the credentials do not persist, and GitHub authentication fails.
What I Tried
1. Setting the PAT using gitcreds::gitcreds_set()
:
-
As an admin user, I run
gitcreds::gitcreds_set()
. I enter the PAT, and it works. I can verify it withgitcreds::gitcreds_get()
and use it for GitHub operations likeusethis::create_from_github()
-
As a non-admin user, I run the same commands, but the credentials do not persist. Even when creating a new PAT, it does now rok. Here’s an example:
> usethis::create_github_token()
☐ Call gitcreds::gitcreds_set() to register this token in the local Git credential store.
ℹ It is also a great idea to store this token in any password-management software that you use.
✔ Opening URL
<https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=DESCRIBE THE
TOKEN'S USE CASE>.
> usethis::create_github_token()
☐ Call gitcreds::gitcreds_set() to register this token in the local Git credential store.
ℹ It is also a great idea to store this token in any password-management software that you use.
✔ Opening URL
<https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=DESCRIBE THE
TOKEN'S USE CASE>.
> gitcreds::gitcreds_set()
? Enter password or token: ghp_XXXXXXXXXXnot_sharingXXXXXXXXXXXXXXXXX
-> Adding new credentials...
-> Removing credentials from cache...
-> Done.
> usethis::gh_token_help()
• GitHub host: "https://github.com"
• Personal access token for "https://github.com": <unset>
☐ To create a personal access token, call usethis::create_github_token().
☐ To store a token for current and future use, call gitcreds::gitcreds_set().
ℹ Read more in the Managing Git(Hub) Credentials article.
2. Setting the token explicitly in the R session:
- Using `Sys.setenv(GITHUB_PAT = “ghp_XXXXXXXXXXnot_sharingXXXXXXXXXXXXXXXXX”) works temporarily, but this is not a permanent solution.
Environment
- OS: Windows 10 Pro, version 22H2
- RStudio Version: 2024.9.1.394
- R Version: 4.3.0
- Git Version: 2.45.2.windows.1
- GitHub PAT: Classic token with
repo
,workflow
, anduser
scopes.
Program paths in Windows
> normalizePath(R.home())
[1] "C:\Program Files\R\R-4.3.0"
> normalizePath(Sys.which("git"))
[1] "C:\Program Files\Git\cmd\git.exe"
What I Suspect
I believe this is a permissions issue with the credential storage mechanism. When running RStudio as an admin, the credentials are stored in a location that is inaccessible to the non-admin user. However, I am unsure how to configure the system so that the non-admin user can securely store and access the credentials.
What I Need Help With
- How can I configure RStudio or Windows so that the non-admin user can securely store and access the GitHub PAT?
- Is there a way to adjust permissions for the credential storage mechanism (e.g., Windows Credential Manager or Git configuration) to resolve this issue?
What I Want to Avoid
- Storing the PAT in
.Renviron
or usingSys.setenv()
as these are less secure. - Running RStudio as an administrator every time.
Any Suggestions?
I would appreciate any guidance on how to resolve this issue or insights into how RStudio and gitcreds
handle credential storage on Windows.