DEV Community

Cover image for Remotely access an Elasticsearch server using SSH tunnel
Romain Norberg
Romain Norberg

Posted on

Remotely access an Elasticsearch server using SSH tunnel

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

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

Discussion (1)

ajmeyghani profile image
AJ Meyghani

Thanks for the tip!