cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect to Neo4j database hosted on Virtual Machine

I have a virtual machine that i can access via SSH with ssh username@ipv4. I installed neo4j there and can access localhost on the machine, but I wasn't able to connect it to my machine through SSH via python. I am able to connect to the virtual machine using sshtunnel library (example 1), but then I can't connect to Neo4j because I don't know how to obtain the URI to connect to their python driver. How can I get the URI to access the neo4j database?

Here is my code

import logging
import sshtunnel
from sshtunnel import SSHTunnelForwarder
import sys
from neo4j import GraphDatabase

ssh_host = 'xyz.xyz.xyz.xyz'
ssh_username = 'username'
ssh_password = 'password'

def open_ssh_tunnel(verbose=False):
    """Open an SSH tunnel and connect using a username and password.

    :param verbose: Set to True to show logging
    :return tunnel: Global SSH tunnel connection
    """

    if verbose:
        sshtunnel.DEFAULT_LOGLEVEL = logging.DEBUG

    global tunnel
    tunnel = SSHTunnelForwarder(
        (ssh_host, 22),
        ssh_username = ssh_username,
        ssh_password = ssh_password,
        remote_bind_address = ('127.0.0.1', 7687)
    )

    tunnel.start()


def close_ssh_tunnel():
    """Closes the SSH tunnel connection.
    """

    tunnel.close

open_ssh_tunnel()

#How do i get URI? tunnel.local_bind_port does not work
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))
driver.close()
close_ssh_tunnel()
0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.