SSH tunneling is required when you want to access services like MySQL or OpenSearch from your local machine, as these services are not accessible from the outside. With an SSH tunnel, you can create a secure channel between your local machine and the remote server.
ssh -p2222 -L<local port>:<target host>:<target port> <user>@<server>
In this command, replace <local port> with your chosen local port number, <target host> and <target port> depend on the service you're trying to access. MySQL only takes connections from localhost, while OpenSearch and Elasticsearch both take connections from the $VHOSTIP.
This will open a ssh connection to the server, while this window is open you can interact with the service on the specified port.
#mysql
ssh -p2222 -L 3307:127.0.0.1:3306 $USER@$SERVER
#OpenSearch
ssh -p2222 -L 9200:$VHOSTIP:9200 $USER@$SERVER
#Redis-cache
ssh -p2222 -L 6379:/home/$USER/.config/redis/run/redis-cache.sock $USER@$SERVER
After setting up the tunnel, you can connect to the service just like you would on the server itself using the local port:
#mysql
mysql -h127.0.0.1 -P3307 -p -u $USER
#OpenSearch or Elasticsearch (Use localhost with the local port instead of $VHOSTIP)
curl "http://localhost:9200/_cluster/health?pretty"
#Redis (Use localhost with the local port instead of socket file path)
redis-cli -n 0 -h 127.0.0.1 -p 6379
Was dit artikel nuttig?
Dat is fantastisch!
Hartelijk dank voor uw beoordeling
Sorry dat we u niet konden helpen
Hartelijk dank voor uw beoordeling
Feedback verzonden
We stellen uw moeite op prijs en zullen proberen het artikel te verbeteren