Node.js not available via ssh

I am trying to invoke the installation of node.js on a remote server running Ubuntu via SSH. Node was installed via nvm.

SSHing and calling Node works just fine:

user@localmachine :~$ ssh user@remoteserver (Server welcome text) user@remoteserver :~$ which node /home/user/.nvm/v0.10.00/bin/node 

However, if I combine it into one line:

 user@localmachine :~$ ssh user@remoteserver "which ls" /bin/ls user@localmachine :~$ ssh user@remoteserver "which node" 

No sign of node, so I tried to find .bashrc and wait 10 seconds:

 user@localmachine :~$ ssh user@remoteserver "source ~/.bashrc; sleep 10; which node" 

This is affected only by Node. One thing I noticed is that if I go down and then check which shell I -bash , and if I'm ssh direct, this gives me /bin/bash . I tried to run commands inside the bash shell:

 user@localmachine :~$ ssh user@remoteserver 'bash --login -c "which node"' 

Still nothing.

Basically my question is: Why doesn't bash detect my node.js installation when I call it silently from SSH?

+6
source share
2 answers
 $ ssh user@remoteserver "which node" 

When you run ssh and specify the command to run on the remote system, by default ssh does not allocate PTY (pseudo-TTY) for the session. Without TTY, your remote shell process (i.e. bash) is initialized as a non-interactive session instead of an interactive session. This may change the way interpreting initialization files - bashrc, .bash_profile, etc.

The actual problem is probably that the line adding /home/user/.nvm/v0.10.00/bin to your PATH command is not executed for non-interactive sessions. This can be solved in two ways:

  • Locate the command in the initialization file, which adds /home/user/.nvm/v0.10.00/bin to your path to the command, finds out why it does not work for non-interactive sessions and fixes it.

  • Run ssh with the -t option. This indicates that PTY is allocated for the remote session. Or add the RequestTTY yes line to your .ssh/config file on the local host.

+3
source

Another approach is to run bash interactively with the -i flag:

 user@localmachine :~$ ssh user@remoteserver "bash -i -c 'which node'" /home/user/.nvm/v0.10.00/bin/node 
+6
source

Source: https://habr.com/ru/post/986308/


All Articles