-
Notifications
You must be signed in to change notification settings - Fork 699
Open
Labels
Description
I have the following function in my service to connect to my server using ssh:
async executeSSHCommand(command: string): Promise<string> {
const conn = new Client();
const host = this._configService.get('bbb.host', { infer: true });
const privateKey = this._configService.get('bbb.privateKey', { infer: true });
const passphrase = this._configService.get('bbb.passphrase', { infer: true })?.replace(/\\n/g, '\n');
// console.log('Connecting with:', {
// host,
// user: 'root',
// hasKey: privateKey,
// passphrase: passphrase,
// });
return new Promise((resolve, reject) => {
conn.once('ready', () => {
conn.exec(command, (err, stream) => {
if (err) return reject(err);
let output = '';
stream.on('data', (data) => (output += data.toString()));
stream.on('close', (code) => {
conn.end(); // kończymy połączenie dopiero po zakończeniu komendy
if (code !== 0) return reject(`Command failed with code: ${code}`);
resolve(output);
});
});
});
conn.on('error', (err) => reject(err));
conn.connect({ host, port: 22, username: 'root', privateKey, passphrase });
});
}
Unfortunately, while it works fine in development, it does not work in production (digital ocean app) - I have an error:
Timed out while waiting for handshake
Any ideas how to fix that?