Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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