mscdex/ssh2

Cannot find the bashrc source configuration when using ssh2 connect to the server

bodenstandig opened this issue · 3 comments

Hello dear SSH2 community! I am a undergraduate student struggling with my graduate project.

When I was trying execute command 'conda activate env' using the exec() function of SSH2, it returns error bash: conda: command not found, though I have configured the conda well in ~/. bashrc using normal SSH connections before. (username, password, IP and port are exactly the same).

I know I can solve this problem by using other command like "source path-to-conda/activate env" or just configure the bashrc again, but why is that happened? I'm really curious about that and many thanks if anybody can help with that!

mscdex commented

Typical bashrc scripts have checks that return early when bash is being ran in non-interactive mode, which would be the case for exec() (or ssh foo@bar 'some command' when using the OpenSSH client).

Is there any solutions that I can interactively connect to the server using SSH2? Thanks!

mscdex commented

shell() gives you an interactive session that's equivalent to ssh foo@bar with the OpenSSH client. A couple of alternatives include:

  • Simply commenting out the relevant check in the bashrc and continue to use exec()
  • Ensure the SSH server is configured to allow passing of the BASH_ENV environment variable, which you could then point to a custom bashrc that does not have the relevant check. With that, you could then continue to use exec().