Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error authenticating in usethis::create_from_github() #711

Closed
wjakethompson opened this issue Apr 11, 2019 · 3 comments
Closed

Error authenticating in usethis::create_from_github() #711

wjakethompson opened this issue Apr 11, 2019 · 3 comments

Comments

@wjakethompson
Copy link

@wjakethompson wjakethompson commented Apr 11, 2019

There appears to be a problem when authenticating with a password protected ssh on macOS Mojave (10.14.4). Not sure if this is a problem in usethis, git2r, or my local setup. When I try to create_from_github I get the following error:

usethis::create_from_github("wjakethompson/jayhawkdown")
#> ✔ Cloning repo from 'git@github.com:wjakethompson/jayhawkdown.git' into '/Users/w449t405/Desktop/jayhawkdown'
#> Error in git2r::clone(origin_url, repo_path, credentials = credentials, : Error in 'git2r_clone': error authenticating:

Created on 2019-04-11 by the reprex package (v0.2.1)

This occurs for other GitHub related functions as well (e.g., use_github). As far as I can tell, git2r is set up correctly:

usethis::git_sitrep()
#> Git user
#> * Name: 'Jake Thompson'
#> * Email: 'wjakethompson@gmail.com'
#> * Vaccinated: TRUE
#> usethis + git2r
#> * Default usethis protocol: 'ssh'
#> * git2r supports SSH: TRUE
#> * Credentials: '<usethis + git2r default behaviour>'
#> GitHub
#> * Personal access token: '<found in env var>'
#> * User: 'wjakethompson'
#> * Name: 'Jake Thompson'
#> Repo
#> ℹ No active usethis project.

git2r::libgit2_features()
#> $threads
#> [1] TRUE
#> 
#> $https
#> [1] TRUE
#> 
#> $ssh
#> [1] TRUE

Created on 2019-04-11 by the reprex package (v0.2.1)

If I specify my credentials, I get prompted for my password, but then things work as expected:

cred <- git2r::cred_ssh_key()

usethis::create_from_github("wjakethompson/jayhawkdown", credentials = cred)
#> ✔ Creating '/Users/w449t405/Desktop/jayhawkdown/'
#> ✔ Cloning repo from 'git@github.com:wjakethompson/jayhawkdown.git' into '/Users/w449t405/Desktop/jayhawkdown'
#> ✔ Setting active project to '/Users/w449t405/Desktop/jayhawkdown'
#> ✔ Opening '/Users/w449t405/Desktop/jayhawkdown/' in new RStudio session
#> ✔ Setting active project to '<no active project>'

Here is some additional session information that may be helpful:

devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.5.2 (2018-12-20)
#>  os       macOS Mojave 10.14.4        
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/Chicago             
#>  date     2019-04-11                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                         
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.5.2)                 
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.5.2)                 
#>  callr         3.2.0      2019-03-15 [1] CRAN (R 3.5.2)                 
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.5.2)                 
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.0)                 
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.5.0)                 
#>  devtools      2.0.2      2019-04-08 [1] CRAN (R 3.5.2)                 
#>  digest        0.6.18     2018-10-10 [1] CRAN (R 3.5.0)                 
#>  evaluate      0.13       2019-02-12 [1] CRAN (R 3.5.2)                 
#>  fs            1.2.7      2019-03-19 [1] CRAN (R 3.5.2)                 
#>  glue          1.3.1      2019-04-03 [1] Github (tidyverse/glue@f356a12)
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.5.2)                 
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.0)                 
#>  knitr         1.22       2019-03-08 [1] CRAN (R 3.5.2)                 
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.0)                 
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.5.0)                 
#>  pkgbuild      1.0.3      2019-03-20 [1] CRAN (R 3.5.2)                 
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.5.0)                 
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.0)                 
#>  processx      3.3.0      2019-03-10 [1] CRAN (R 3.5.2)                 
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.5.0)                 
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.5.2)                 
#>  Rcpp          1.0.1      2019-03-17 [1] CRAN (R 3.5.2)                 
#>  remotes       2.0.4      2019-04-10 [1] CRAN (R 3.5.2)                 
#>  rlang         0.3.4      2019-04-07 [1] CRAN (R 3.5.2)                 
#>  rmarkdown     1.12       2019-03-14 [1] CRAN (R 3.5.2)                 
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.0)                 
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.5.0)                 
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.5.2)                 
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.5.2)                 
#>  testthat      2.0.1      2018-10-13 [1] CRAN (R 3.5.0)                 
#>  usethis       1.5.0.9000 2019-04-11 [1] Github (r-lib/usethis@5c662d7) 
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.5.0)                 
#>  xfun          0.6.1      2019-04-08 [1] Github (yihui/xfun@43a56f5)    
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.0)                 
#> 
#> [1] /Users/w449t405/R
#> [2] /Library/Frameworks/R.framework/Versions/3.5/Resources/library

Created on 2019-04-11 by the reprex package (v0.2.1)

@jennybc
Copy link
Member

@jennybc jennybc commented Apr 11, 2019

This is exactly why the use_git_credentials() function was created.

#> usethis + git2r
#> * Default usethis protocol: 'ssh'
#> * git2r supports SSH: TRUE
#> * Credentials: '<usethis + git2r default behaviour>'

I'm afraid this doesn't assure you that git2r can find your credentials, it just means you're sending the default NULL SSH credential and git2r does its thing. Which can't really be debugged or studied. The way we know it's not working is that it ... doesn't work 😬

So you are one of the people who may need to explicitly create a credential, just as you successfully do above, and cache it for entire sessions via use_git_credentials(). Then all usethis functions will use that credential for git operations.

Alternatives include: not having an SSH passphrase on your keys or using HTTPS.

It is on the usethis roadmap to switch to the credentials package, internally, so that we have more control and visibility into this process. Right now, we are flying blind when git2r doesn't discover SSH keys and/or can't obtain the passphrase.

@jennybc jennybc closed this as completed Apr 11, 2019
@jennybc
Copy link
Member

@jennybc jennybc commented Apr 11, 2019

I will say that it sounds like the SSH passphrase is what git2r is failing to obtain automatically. So you might want to look into your configuration there, because most people are able to get git2r working with SSH on macOS (less true on Windows).

Section 11.4.3.1 here has some guidance on configuring ssh-agent + keychain to manage the SSH passphrase on macOS:

https://happygitwithr.com/ssh-keys.html#create-an-ssh-key-pair

@wmoldham
Copy link

@wmoldham wmoldham commented Apr 27, 2019

I apologize for this is a naive comment, but thought I would share in case someone could make something of these observations. I have been dealing with these precise problems for the past couple of hours on my Mac running Mojave 10.14.4. I have been scrupulously following the guidelines from https://happygitwithr.com/ssh-keys.html without success. While I was able to connect to git via ssh using the shell without difficulties, I was unable to use any functions within R that depended on git2r. I noticed that, when creating ssh keys in the shell and subsequently adding them to the ssh-agent via ssh-add -K ~/.ssh/id_rsa, I was not being challenged for the passphrase. FWIW, out of habit, I was using as a passphrase the password associated with my Mac's user account. Nonetheless, when I generated new keys using a completely random passphrase, I was subsequently challenged for the passphrase when adding to the ssh-agent and, immediately following this, was successfully able to create an online repo from my active project using use_github(). The positive effects seem durable after a software restart, but I have not tested al lof the git2r functions described above. As you can imagine, over the past couple of hours I tried several different things, but I don't think there was anything materially different this time things worked aside from changing up the passphrase when I generated the keys. HTH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants