0

I have been using shelljs to execute certain set of commands. So i tried to connect to a remote ubuntu server over ssh via shelljs. This is my nodejs file.

var shelljs = require('shelljs');
shelljs.exec('ssh -i [path/to/pem/file] ubuntu@[taregt_ip]');

But i get this error:

Pseudo-terminal will not be allocated because stdin is not a terminal.

So how to solve this issue or is there any other utility to connect to ssh with one single command.

EDIT: the link you guys are posting for me to refer in not the duplicate of my problem.

Satnam Sandhu
  • 610
  • 1
  • 10
  • 25
  • 1
    Possible duplicate of [Pseudo-terminal will not be allocated because stdin is not a terminal](https://stackoverflow.com/questions/7114990/pseudo-terminal-will-not-be-allocated-because-stdin-is-not-a-terminal) – Derek Brown Dec 10 '17 at 15:02

1 Answers1

1

SSH doesn't always allocate a pseudo-terminal. That is explained in this existing answer. You should add the -tt flag to force this.

That said, I wouldn't use shelljs to do ssh. As you are just executing a local binary, this solution a) is not portable and b) will not know how to parse errors or deal with unexpected output. I have used ssh2 in the past for similar projects, as it has an interactive SSH option, which makes it easy to create streams (STDOUT and STDIN) from an SSH connection.

Derek Brown
  • 4,232
  • 4
  • 27
  • 44
  • I have seen [this link](https://stackoverflow.com/questions/7114990/pseudo-terminal-will-not-be-allocated-because-stdin-is-not-a-terminal), but didn't find it useful. `ssh2` seemed to the right choice but it throws this error. `Timed out while waiting for handshake` – Satnam Sandhu Dec 10 '17 at 15:43
  • @Satnam run it in verbose mode. I would imagine there is a problem with your SSL config, which is why both are giving you issues. – Derek Brown Dec 10 '17 at 16:54