How to Run SSH Command with Login Shell

66 Views Asked by At

I have Node.js installed by NVM on server and it doesn't work with SSH. It shows node: command not found in non-login shell.

For example, this won't work

ssh server1 <<doc
    node -v
doc

This doesn't work too

ssh server1 <<<"bash -l; node -v"

The NVM init is inside .bashrc so I tried to source it but still not ok

ssh server1 <<doc
    source /etc/profile
    source ~/.bashrc
    node -v
doc

The only way to make it work is forcing ssh using TTY

ssh -tt server1 <<doc
    node -v
doc

However, the script is long and I don't wish to see the shell printing out every command. Even after add 'set +x' to top of script it still prints out every command.

And -tt will force TTY and the ssh command doesn't stop. Add 'exit' to the end of script is ok but still the issue of printing out command above.

How to do ssh without -tt and just as in login shell?

0

There are 0 best solutions below