Open brolly759 opened 6 years ago
If I type this directly in the terminal I can successfully connect and do a reverse SSH: ssh -f -N -T -R22222:localhost:22 xx.xxx.xx.x
I tried 1987 and 22222 port and nothing mattered with this library code, I couldn't connect.
anything?
i found it not work too. but you can use the ssh2 package directly:
var Client = require('ssh2').Client;
const Socket = require('net').Socket;
var conn = new Client();
var remotePort = 8081;
var remoteIP = 'xxxx';
var remoteUser = 'ec2-user';
conn
.on('error', function(e) {
console.log('ssh reverse forward error', e);
})
.on('ready', function() {
console.log('Client :: ready');
conn.forwardIn('127.0.0.1', remotePort, function(err) {
if (err) {
// errors.push(err);
throw err;
}
console.log('Listening for connections on server on port remotePort!');
});
})
.on('tcp connection', function(info, accept, reject) {
console.log('TCP :: INCOMING CONNECTION:');
console.dir(info);
var srcSocket = new Socket();
srcSocket.connect(remotePort, 'localhost', function() {
var remote = accept();
console.log('accept remote connection');
srcSocket.pipe(remote).pipe(srcSocket);
});
})
.connect({
host: remoteIP,
port: 22,
username: remoteUser,
privateKey: fs.readFileSync('./sh-key'),
});
I keep getting "ssh_exchange_identification: Connection closed by remote host" when trying to connect to the device. I get verification the tunnel has been created but I cannot seem to login. Here is the code on the node I want to connect too:
`var tunnel = require('reverse-tunnel-ssh');
// This is a very handy way to test your next webhook !
// Please set up your /etc/hosts or change the hostname befor // running the example.
var config = { host: 'xx.xx.xx.x', username: 'root', password: 'some_pass', dstHost: '0.0.0.0', // bind to all interfaces (see hint in the readme) dstPort: 1987, //srcHost: '127.0.0.1', // default //srcPort: dstPort // default is the same as dstPort }
tunnel(config, function(error, clientConnection) { console.log(clientConnection._forwarding); });
require('http').createServer(function(res, res){ res.end('SSH-TUNNEL: Gate to heaven !'); }).listen(config.dstPort);
console.log('Tunnel created: http://'+config.host+':'+config.dstPort);`