# Using Packer with local SSH

**URL:** <https://discuss.hashicorp.com/t/using-packer-with-local-ssh/21646>\
**Category:** Packer\
**Created:** [March 3, 2021, 7:24pm UTC](https://discuss.hashicorp.com/t/using-packer-with-local-ssh/21646 "2021-03-03T19:24:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonmccallister](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jasonmccallister/32/12567_2.png) [@jasonmccallister](https://discuss.hashicorp.com/u/jasonmccallister)\
**Post date:** [March 3, 2021, 7:24pm UTC](https://discuss.hashicorp.com/t/using-packer-with-local-ssh/21646/1 "2021-03-03T19:24:52Z")

</div>

I have a computer that is sitting on my network, its running Ubuntu and I can connect with SSH. I would like to use Packers `null` builder and define the communicator to provision the server but it is hung up on waiting for the SSH connection.

Here is the `local.pkr.hcl` file:

```auto
source "null" "remote" {
  ssh_host = "192.168.7.191"
  ssh_username = "ubuntu"
  ssh_password = "ubuntu"
  communicator = "ssh"
}

build {
  sources = ["sources.null.remote"]

  provisioner "shell" {
    inline = ["echo whoami"]
  }

  provisioner "shell-local" {
    inline = ["echo whoami"]
  }
}

```

Is this supported and is there a way to tell the communicator to use my local SSH key?

---

<div class="post-metadata">

**Author:** ![jasonmccallister](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jasonmccallister/32/12567_2.png) [@jasonmccallister](https://discuss.hashicorp.com/u/jasonmccallister)\
**Post date:** [March 3, 2021, 7:43pm UTC](https://discuss.hashicorp.com/t/using-packer-with-local-ssh/21646/2 "2021-03-03T19:43:00Z")

</div>

I don’t think its well documented, but here is the working version with variables:

```auto
variable "host" {
    type = string
}

variable "private_key" {
    type = string
    default = "~/.ssh/id_rsa"
}

source "null" "remote" {
  ssh_host = var.host
  ssh_username = "ubuntu"
  ssh_private_key_file = var.private_key
  communicator = "ssh"
}

build {
  sources = ["sources.null.remote"]

  provisioner "shell" {
    inline = ["whoami"]
  }

  provisioner "shell-local" {
    inline = ["whoami"]
  }
}

```

---

<div class="post-metadata">

**Author:** ![lists](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lists/32/16797_2.png) [@lists](https://discuss.hashicorp.com/u/lists)\
**Post date:** [May 25, 2022, 12:12pm UTC](https://discuss.hashicorp.com/t/using-packer-with-local-ssh/21646/3 "2022-05-25T12:12:56Z")

</div>

Thanks for sharing, unfortunately that didn’t work for me today.  
I was more successful by setting “ssh\_agent\_auth” in my source-def:

```auto
source "null" "remote" {
  ssh_host = "172.31.91.12"
  ssh_username = "vagrant"
  ssh_agent_auth = "true"
  communicator = "ssh"
}

```
