loading...
Cover image for Remotely access an Elasticsearch server using SSH tunnel

Remotely access an Elasticsearch server using SSH tunnel

romainnorberg profile image Romain Norberg ・1 min read

If you have an Elasticsearch server which is not accessible from outside but you have SSH access to it, you can create a tunnel to connect to it.

Open your terminal and create the tunnel by tipping:

$ ssh -i <identity_file_path> user@<remote_server> -L 9200:<remote_server_local_elastic_ip>:9200 -N -v

Next, on another windows, try to get Elasticsearch details:

$ curl -XGET http://127.0.0.1:9200/?pretty

It should returns something like that:

{
  "name" : "staging",
  "cluster_name" : "lf_staging_cluster",
  "cluster_uuid" : "xxxxx",
  "version" : {
    "number" : "7.6.2",
    ...
  },
  "tagline" : "You Know, for Search"
}

By example, I've a local ssh config that allow me to connect to remote server only with their alias.

~/.ssh/config

Host staging
  HostName 54.22.123.123
  User debian

So I can open remote tunnel easily by tipping short command like (using my default ssh key)

$ ssh staging -L 9200:localhost:9200 -N -v

It works as well on MacOs as Windows, don't hesitate to send me your comments and/or tips about the subject

Posted on May 15 by:

romainnorberg profile

Romain Norberg

@romainnorberg

NO FULL STACK... BUT PROBLEM SOLVER DEVELOPER Php developer, play with Symfony and PhalconPhp frameworks. More on LinkedIn or Github

Discussion

markdown guide