title: golang ssh dial timeout
body: <p>What is the best way to create DialTimeout on ssh connection? For example, this code always returns "Ping deadline exceed":</p>
  
  <pre><code>func (t *Tunnel) ping(sshConn *ssh.Client, addr string) (net.Conn, error) {
      var (
          conn net.Conn
          err  error
          done chan int
      )
      go func() {
          time.Sleep(getSeconds(10))
          err = errors.New("Ping deadline exceed")
          log.Printf("%v\nStatus: bad %s -&gt; %s", err, t.serverAddr, addr)
          t.writeStatus(bad)
          done &lt;- 1
          close(done)
      }()
      go func() {
          conn, err = sshConn.Dial("tcp", addr)
          if err != nil {
              t.writeStatus(bad)
              log.Printf("%v\nStatus: bad %s -&gt; %s", err, t.serverAddr, addr)
          }
          done &lt;- 1
          close(done)
      }()
      &lt;-done
      return conn, err
  }
  </code></pre>
  
  <p>PS Timeout in ssh.ClientConfig is set to 5 seconds</p>