Template To Control Server Through SSH Tunnel With Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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