Skip to content

SSH authentication fails #6

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

Closed
chrissound opened this issue Jun 9, 2019 · 4 comments
Closed

SSH authentication fails #6

chrissound opened this issue Jun 9, 2019 · 4 comments

Comments

@chrissound
Copy link

chrissound commented Jun 9, 2019

Hello! First off, thank you for the project!

I'm not too familiar with Terraform so maybe I'm doing something dumb. I've essentially copied example to another directory and modified the deploy_nixos.tf file.

Previous to the I ran eval "$(ssh-agent -s)" and ssh-add ~/.ssh/id_rsa.

Error: Error applying plan:

1 error occurred:
    * module.deploy_nixos.null_resource.deploy_nixos: timeout - last error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
data "google_compute_network" "default" {
  name = "default"
}

resource "google_compute_firewall" "deploy-nixos" {
  name    = "deploy-nixos"
  network = "${data.google_compute_network.default.name}"

  allow {
    protocol = "icmp"
  }

  // Allow SSH access
  allow {
    protocol = "tcp"
    ports    = ["22", "80", "443"]
  }

  source_tags = ["nixos"]
}

resource "google_compute_instance" "deploy-nixos" {
  name         = "deploy-nixos-example"
  machine_type = "g1-small"
  zone         = "europe-west2-a"
  # region      = "eu-west2"

  // Bind the firewall rules
  tags = ["nixos"]

  boot_disk {
    initialize_params {
      // Start with an image the deployer can SSH into
      image = "${module.nixos_image_custom.self_link}"
      size  = "25"
    }
  }

  network_interface {
    network = "default"

    // Give it a public IP
    access_config {}
  }

  lifecycle {
    // No need to re-deploy the machine if the image changed
    // NixOS is already immutable
    ignore_changes = ["boot_disk"]
  }
}

module "deploy_nixos" {
  source = "../../deploy_nixos"

  // Deploy the given NixOS configuration. In this case it's the same as the
  // original image. So if the configuration is changed later it will be
  // deployed here.
  nixos_config = "${path.module}/image_nixos_custom.nix"

  target_user = "root"
  target_host = "${google_compute_instance.deploy-nixos.network_interface.0.access_config.0.nat_ip}"

  triggers = {
    // Also re-deploy whenever the VM is re-created
    instance_id = "${google_compute_instance.deploy-nixos.id}"
  }
}

If I manually try to SSH I get the same authentication error. I've mounted the disk on another instance and inspecting /root shows no .ssh directory:

root@instance-2:/home/chris/mount/root# ls -altr
total 12
drwx------  3 root root 4096 Jun  8 20:47 .
drwx------  2 root root 4096 Jun  8 20:47 .nix-defexpr
drwxr-xr-x 16 root root 4096 Jun  8 21:09 ..
@zimbatm
Copy link
Member

zimbatm commented Jun 11, 2019

Do you have the $SSH_AUTH_SOCK environment variable set? This is needed by the SSH client to talk to the agent.

@chrissound
Copy link
Author

Yup that is set by eval "$(ssh-agent -s)":

echo $SSH_AUTH_SOCK  
/tmp/ssh-Wpyng4AamOwb/agent.25936

@zimbatm
Copy link
Member

zimbatm commented Jun 12, 2019

It could be a number of things:

  • the target_host IP isn't reachable
  • the NixOS VM image didn't start the SSH server (look at the console logs of the VM)
  • firewalling issue

@chrissound
Copy link
Author

Just tried this again and it just worked fine - without any changes. So maybe I did mess up the ssh-agent part earlier, not sure.

Thanks for the pointers @zimbatm .

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

2 participants