diff --git a/communicator/ssh/provisioner.go b/communicator/ssh/provisioner.go index f9f889037e..48eaafe388 100644 --- a/communicator/ssh/provisioner.go +++ b/communicator/ssh/provisioner.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform/helper/pathorcontents" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/mapstructure" + "github.com/xanzy/ssh-agent" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" ) @@ -245,22 +246,17 @@ func connectToAgent(connInfo *connectionInfo) (*sshAgent, error) { return nil, nil } - sshAuthSock := os.Getenv("SSH_AUTH_SOCK") - - if sshAuthSock == "" { - return nil, fmt.Errorf("SSH Requested but SSH_AUTH_SOCK not-specified") - } - - conn, err := net.Dial("unix", sshAuthSock) + agent, conn, err := sshagent.New() if err != nil { - return nil, fmt.Errorf("Error connecting to SSH_AUTH_SOCK: %v", err) + return nil, err } // connection close is handled over in Communicator return &sshAgent{ - agent: agent.NewClient(conn), + agent: agent, conn: conn, }, nil + } // A tiny wrapper around an agent.Agent to expose the ability to close its @@ -271,6 +267,10 @@ type sshAgent struct { } func (a *sshAgent) Close() error { + if a.conn == nil { + return nil + } + return a.conn.Close() } diff --git a/website/source/docs/provisioners/connection.html.markdown b/website/source/docs/provisioners/connection.html.markdown index 83fa8ebb4a..52f7be7589 100644 --- a/website/source/docs/provisioners/connection.html.markdown +++ b/website/source/docs/provisioners/connection.html.markdown @@ -73,7 +73,9 @@ provisioner "file" { function](/docs/configuration/interpolation.html#file_path_). This takes preference over the password if provided. -* `agent` - Set to false to disable using ssh-agent to authenticate. +* `agent` - Set to false to disable using ssh-agent to authenticate. On Windows the + only supported SSH authentication agent is + [Pageant](http://the.earth.li/~sgtatham/putty/0.66/htmldoc/Chapter9.html#pageant) **Additional arguments only supported by the "winrm" connection type:**