title: SSHTunnel for remote access of postgres server
body: <p>I'm new to using postgres as well as ssh and am having some trouble understanding what I need to do to get remote clients accessing a postgres server. Right now I've got one computer with a server running that I can access using psycopg2 but now I want to query the server using another computer. I've looked around and found examples using sshtunneler, but I feel like I'm missing some puzzle pieces.</p>
  
  <pre><code>import psycopg2
  from sshtunnel import SSHTunnelForwarder
  import time
  
  with SSHTunnelForwarder(
           ('192.168.1.121', 22),
           ssh_password="????",
           ssh_username="????",
           remote_bind_address=('127.0.0.1', 5432)) as server:
  
      conn = psycopg2.connect(database="networkdb",port=server.local_bind_port)
      curs = conn.cursor()
      sql = "select * from Cars"
      curs.execute(sql)
      rows = curs.fetchall()
      print(rows)
  </code></pre>
  
  <p>My first confusion is I'm not sure what username/password should be. I downloaded putty and put the remote address info in the tunnel section using this <a href="http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html" rel="nofollow noreferrer">tutorial</a> but I have no idea if that's doing anything. When I try to start the server I get the error </p>
  
  <pre><code>2017-03-03 10:03:28,742| ERROR   | Could not connect to gateway 192.168.1.121:22 : 10060
  </code></pre>
  
  <p>Any sort of help/explanation of what I need to do would be appreciated.</p>
  
  <p>If I can do it without ssh then that would be better. Currently running this:</p>
  
  <pre><code>psycopg2.connect(dbname='networkinfodb',  user='postgres', host='168.192.1.121', password='postgres', port=5432)
  </code></pre>
  
  <p>outputs...</p>
  
  <p>OperationalError                          Traceback (most recent call last)
   in ()
  ----> 1 psycopg2.connect(dbname='networkinfodb',  user='postgres', host='168.192.1.121', password='postgres', port=5432)</p>
  
  <pre><code>OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
      Is the server running on host "168.192.1.121" and accepting
      TCP/IP connections on port 5432?
  </code></pre>
  
  <p>and I'm not sure where to go to figure out what the issue is.</p>