Skip to content

Instantly share code, notes, and snippets.

@pirosuke
Created January 19, 2019 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirosuke/61982e4811fde4ce142749b5931c5c33 to your computer and use it in GitHub Desktop.
Save pirosuke/61982e4811fde4ce142749b5931c5c33 to your computer and use it in GitHub Desktop.
Template To Control Server Through SSH Tunnel With Node.js
const tunnel = require('tunnel-ssh');
async function main() {
const sshUserName = 'SSH_USER_NAME';
const sshPassword = 'SSH_PASSWORD';
let sshConfig = {
host: 'SSH_HOST_ADDRESS',
port: SSH_PORT,
username: sshUserName,
password: sshPassword,
keepaliveInterval: 60000,
keepAlive: true,
dstHost: 'TUNNEL_DEST_HOST_ADDRESS',
dstPort: TUNNEL_DEST_PORT,
localHost: 'localhost',
localPort: LOCAL_PORT
};
const tnl = tunnel(sshConfig, async (err: any, server: any) => {
if (err) {
throw err;
}
// write what you want to do through tunnel.
tnl.close();
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment