Authentication issue in git2r_push
Hi,
I have set an SSH key pair (without passphrase) in RStudio and am getting this error when I try to push changes using git2r to GitHub:
Error in 'git2r_push': Unable to authenticate with supplied credentials
A similar issue has been discussed in #152, and @mik3y64's https://github.com/ropensci/git2r/issues/399#issuecomment-522950677 solution---of first pushing using RStudio git GUI before git2r_pushing---didn't help (although the GUI's pull/push work properly).
What can be done?
Thanks in advance!
I'm running into the same issue with CRAN version 0.26.1 and dev version 0.26.1.9000
@rappster Are you using SSH keys for authentication? If yes, do the SSH keys have a passphrase? Can you try the following and report the results?
library(git2r)
push()
push(credentials = cred_ssh_key())
@jdblischak thanks for getting back to me on this.
Turns out I'm not using a passphrase - even though I probably should, so this was a good reminder ;-)
I'm having trouble running a reprex due to working directory issues when using reprex::reprex(), but here's the code I ran manually annotated:
library(git2r)
remote_add(name = "origin", url = "https://github.com/rappster/git2rtest")
current_status <- status()
add(path = unlist(current_status))
commit(message = "Test")
# [b0a75c8] 2020-04-30: Test
push(
name = "origin",
refspec = "refs/heads/master",
set_upstream = TRUE
)
# Error in push(name = "origin", refspec = "refs/heads/master", set_upstream = TRUE) :
# Error in 'git2r_push': Unable to authenticate with supplied credentials
push(
name = "origin",
refspec = "refs/heads/master",
credentials = cred_ssh_key(),
set_upstream = TRUE
)
# Error in push(name = "origin", refspec = "refs/heads/master", credentials = cred_ssh_key(), :
# Error in 'git2r_push': Unable to authenticate with supplied credentials
cred_ssh_key()
# $publickey
# [1] "/home/janko/.ssh/id_rsa.pub"
#
# $privatekey
# [1] "/home/janko/.ssh/id_rsa"
#
# $passphrase
# character(0)
#
# attr(,"class")
# [1] "cred_ssh_key"
My session info
> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────
setting value
version R version 3.6.1 (2019-07-05)
os Pop!_OS 19.10
system x86_64, linux-gnu
ui RStudio
language en_US:en
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Berlin
date 2020-04-30
─ Packages ───────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1)
callr 3.4.0 2019-12-09 [1] CRAN (R 3.6.1)
cli 2.0.1 2020-01-08 [1] CRAN (R 3.6.1)
clipr 0.7.0 2019-07-23 [1] CRAN (R 3.6.1)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1)
digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.1)
evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1)
fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.1)
fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.1)
git2r * 0.26.1.9000 2020-04-27 [1] Github (ropensci/git2r@134692d)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.1)
htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
knitr 1.27 2020-01-16 [1] CRAN (R 3.6.1)
processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.1)
ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.1)
R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1)
Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1)
reprex 0.3.0 2019-05-16 [1] CRAN (R 3.6.1)
rlang 0.4.5 2020-03-01 [1] CRAN (R 3.6.1)
rmarkdown 2.0 2019-12-12 [1] CRAN (R 3.6.1)
rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.6.1)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1)
whisker 0.4 2019-08-28 [1] CRAN (R 3.6.1)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1)
xfun 0.12 2020-01-13 [1] CRAN (R 3.6.1)
[1] /home/janko/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library
@rappster Thanks for the information. So unfortunately the trick that worked in https://github.com/jdblischak/workflowr/pull/203 didn't work for you.
Let's see if your key is in OpenSSH or PEM format.
head -n 1 ~/.ssh/id_rsa
It will either say
-----BEGIN OPENSSH PRIVATE KEY-----
or
-----BEGIN RSA PRIVATE KEY-----
For more context see #421
I encounter the same error when running:
push(
name = "origin",
refspec = "refs/heads/master",
credentials = cred_ssh_key(),
set_upstream = TRUE
)
The error:
Error in push(name = "origin", refspec = "refs/heads/master", credentials = cred_ssh_key(), :
Error in 'git2r_push': Unable to authenticate with supplied credentials
When I type i the terminal:
head -n 1 ~/.ssh/id_rsa
I get:
-----BEGIN RSA PRIVATE KEY-----
What can I try next?