May 15th 2020

Remotely access an Elasticsearch server using SSH tunnel

Original post:

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> [email protected]<remote_server> -L 9200:<remote_server_local_elastic_ip>:9200 -N -v

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

$ curl -XGET

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.


Host staging
  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

Romain Norberg

Romain Norberg

Php developer, play with Symfony and PhalconPhp frameworks.
More on LinkedIn or Github