Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Permission denied (publickey). fatal: Could not read from remote repository. #45

Open
akamalov opened this issue Jun 27, 2019 · 9 comments

Comments

@akamalov
Copy link

Environment
Terraform: 0.12.3

Problem

Trying to initialize terraform with terraform-google-consul module version of 0.4.0 - https://github.com/hashicorp/terraform-google-consul/releases/tag/v0.4.0

Getting an error on terraform init:

Initializing modules...
Downloading git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0 for consul_cluster...

Error: Failed to download module

Could not download module "consul_cluster" (main.tf:118) source code from
"git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0": error
downloading
'ssh://git@github.com/hashicorp/terraform-google-consul.git?ref=v0.4.0':
/usr/local/bin/git exited with 128: Cloning into
'.terraform/modules/consul_cluster'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.



Error: Failed to download module

Could not download module "consul_cluster" (main.tf:118) source code from
"git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0": error
downloading
'ssh://git@github.com/hashicorp/terraform-google-consul.git?ref=v0.4.0':
/usr/local/bin/git exited with 128: Cloning into
'.terraform/modules/consul_cluster'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.



Error: Failed to download module

Could not download module "consul_cluster" (main.tf:118) source code from
"git::git@github.com:hashicorp/terraform-google-consul.git?ref=v0.4.0": error
downloading
'ssh://git@github.com/hashicorp/terraform-google-consul.git?ref=v0.4.0':
/usr/local/bin/git exited with 128: Cloning into
'.terraform/modules/consul_cluster'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Here is the snippet of my main.tf file referencing a module:

# ---------------------------------------------------------------------------------------------------------------------
# DEPLOY THE CONSUL SERVER CLUSTER
# Note that we make use of the terraform-google-consul module!
# ---------------------------------------------------------------------------------------------------------------------

module "consul_cluster" {
  source = "git::git@github.com:hashicorp/terraform-google-consul.git//modules/consul-cluster?ref=v0.4.0"
  #source = "git::git@github.com:hashicorp/terraform-google-consul.git//modules/consul-cluster?ref=v0.2.1"

  subnetwork_name = "${google_compute_subnetwork.private_subnet_with_google_api_access.name}"

Not sure what's going on here..

@Etiene
Copy link
Contributor

Etiene commented Jun 28, 2019

Weird! Try again once this PR is merged though #44 and then we will have a look

@KZachariassen
Copy link

Hi,
We are seeing the same thing using terraform v0.12.6.

We are using terraform on windows and we are getting this error if we use SSH, when we change the source to use HTTPS it works.

This does not work

module "test" {
  source = "git::ssh://github.test.io/test/test.git"
}

This works

module "test" {
  source = "git::https://github.test.io/test/test.git"
}

Using git command manually works perfectly. I was suspecting this to be a windows-only problem?

@nhart-alf
Copy link

nhart-alf commented Sep 16, 2019

Hi,

Having the same issue here. Terraform 0.12.8.
Windows 10 1903.

HTTPS works:
module "tags" { source = "git::https://git@github.com/CompanyName/blah-terraform-modules.git//tags?ref=develop"

SSH fails:
module "tags" { source = "git@github.com:CompanyName/blah-terraform-modules.git//tags?ref=develop"

Git works standalone to drag these items over ssh using my ssh key that is set systemwide.
Github Desktop also works for ssh using that same key.

I can only assume that Terraform's call for git is doing something funky with ssh.
Doesn't appear to be any debugging that can be done as it's all encapsulated with Terraform.

Does appear to be windows only, all my colleagues are using Linux with the same tf files without issues.

@nhart-alf
Copy link

nhart-alf commented Sep 16, 2019

Found a way to get this working.
After looking at the Terraform source and other references to this issue, it appears that Terraform needs an environment variable for 'GIT_SSH_COMMAND' instead-of/in-addition-to 'GIT_SSH'.

In addition to this, the implementation of GIT_SSH_COMMAND isn't Windows friendly, so it needs the path to ssh.exe to be escaped for \ characters.
The final value therefore is the below.

GIT_SSH_COMMAND = C:\\Windows\\System32\\OpenSSH\\ssh.exe

All other config remained the same as per my previous comment.

If someone from Hashicorp reads this, it could do with being much more obvious (documented) and possibly a better design for Windows.

@smblee
Copy link

smblee commented Jan 31, 2020

Found a way to get this working.
After looking at the Terraform source and other references to this issue, it appears that Terraform needs an environment variable for 'GIT_SSH_COMMAND' instead-of/in-addition-to 'GIT_SSH'.

In addition to this, the implementation of GIT_SSH_COMMAND isn't Windows friendly, so it needs the path to ssh.exe to be escaped for \ characters.
The final value therefore is the below.

GIT_SSH_COMMAND = C:\\Windows\\System32\\OpenSSH\\ssh.exe

All other config remained the same as per my previous comment.

If someone from Hashicorp reads this, it could do with being much more obvious (documented) and possibly a better design for Windows.

This approach worked for me on windows. I had to run set GIT_SSH_COMMAND=C:\\Windows\\System32\\OpenSSH\\ssh.exe since i use cmder, but thanks for this!

@bamb00
Copy link

bamb00 commented Mar 7, 2020

Hi, I'm seeing the same issue running TF 0.12.21, Ubuntu 16.04.

Error: Failed to download module

Could not download module "storage_blob" (storage_blob.tf:1) source code from
"git@github.com:mycompanyname/infra-modules/terraform-azurerm-blobstorage?ref=sandbox":
error downloading
'ssh://git@github.com/mycompanyname/infra-modules/terraform-azurerm-blobstorage?ref=sandbox':
/usr/bin/git exited with 128: Cloning into
'.terraform/modules/storage_blob'...
Warning: Permanently added the RSA host key for IP address 'xxx.xx.xxx.xxx' to
the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

@snolan-uturn
Copy link

Found a way to get this working.
After looking at the Terraform source and other references to this issue, it appears that Terraform needs an environment variable for 'GIT_SSH_COMMAND' instead-of/in-addition-to 'GIT_SSH'.

In addition to this, the implementation of GIT_SSH_COMMAND isn't Windows friendly, so it needs the path to ssh.exe to be escaped for \ characters.
The final value therefore is the below.

GIT_SSH_COMMAND = C:\\Windows\\System32\\OpenSSH\\ssh.exe

All other config remained the same as per my previous comment.

If someone from Hashicorp reads this, it could do with being much more obvious (documented) and possibly a better design for Windows.

If you're only seeing the issue with Windows, then you are probably seeing what I have discussed here: hashicorp/terraform#19232 (comment)

@dev2648e
Copy link

dev2648e commented Dec 7, 2020

I use pagent, so my env var had to be

GIT_SSH_COMMAND=C:\\Program\ Files\\PuTTY\\plink.exe

@ADTC
Copy link

ADTC commented Nov 23, 2021

This was definitely a problem for me on Windows. To get the SSH working with Terraform, I had to do:

set GIT_SSH_COMMAND=C:\\Windows\\System32\\OpenSSH\\ssh.exe

If you're not sure where your ssh.exe is, try:

where ssh

Note, the above set command only applies in the current session. To apply globally, you need to edit your system or user environment variables.

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

No branches or pull requests

9 participants