The git2r package does not appear to attempt to automatically acquire credentials when calling fetch()
Looking through the source, it does not appear that the fetch function or subsequent call attempts to look up credentials. Whereas defaults are provided when calling cred_ssh_key().
Fetching call
The R function is:
fetch <- function(repo = ".", name = NULL, credentials = NULL,
verbose = TRUE, refspec = NULL) {
invisible(.Call(git2r_remote_fetch, lookup_repository(repo),
name, credentials, "fetch", verbose, refspec))
Which calls a C function, git2r_remote_fetch, that has a call to check if the credentials are good.
if (git2r_arg_check_credentials(credentials))
git2r_error(__func__, NULL, "'credentials'", git2r_err_credentials_arg);
That in turn doesn't appear to care that the credentials are NULL. This supports http and https protocols where no credentials are required.
int git2r_arg_check_credentials(SEXP arg)
{
/* It's ok if the credentials is R_NilValue */
if (Rf_isNull(arg))
return 0;
So it happily continues along and attempts to connect to the repository. The uri specifies SSH as the protocol, and it goes ahead and attempts to use that. Then it fails in libgit2's ssh_agent_auth function.
if (rc != LIBSSH2_ERROR_NONE)
ssh_error(session, "error authenticating");
cred_ssh_key provides defaults
As opposed to cred_ssh_key which is where defaults are provided that provide the functionality you're expecting.
cred_ssh_key <- function(publickey = ssh_path("id_rsa.pub"),
privatekey = ssh_path("id_rsa"),
passphrase = character(0)) {