I build IoT applications on a daily basis at RAZRLAB, and every once in a while, I do need the internal tools to perform some functions on servers, be it executing commands or forwarding ports. For this, I found a neat little tool node-ssh
which helps establish ssh tunnels to servers with key authentication.
Let’s create a new folder and set up a fresh npm
repository
npm init --y
We are going to use the following dependencies:
We will create our SSH tunnel using private key authentication for that we will create an SSH key pair with a passphrase.
I would recommend using your cloud providers SSH key access management to securely manage access to your servers. Click here to know how to manage SSH key access through Digital Ocean.
Now, let’s specify paths and information in the .env
file
## .env
SSH_host=
SSH_user=
SSH_privatekey=
SSH_passphrase=
Environment variable definitions:
SSH_host
: Host IP Address or DNS name of the serverSSH_user
: Host username for logging inSSH_privatekey
: path to the private keySSH_passphrase
: passphrase for the key for an added layer of securityWe will access the server and install a Redis server. We will use an Ubuntu machine and leverage the apt
package manager to install the Redis server.
ssh <username>@<host>
sudo apt-get install redis-server
This will download and install Redis and its dependencies. It will also export a CLI application called redis-cli
to interact with the Redis server.
#nodejs #remote-access #javascript #ssh #web-development