0

I'm trying to load environment modules from a non-interactive remote session, and set environment variables accordingly.

For example, in my bashrc I normally call

module load /path/to/cmake/3.x.x

and when I run "cmake --version" from a login shell I'll see

cmake v3.x.x

However, when I run this with a non-interactive remote session, I see cmake v2.xxx as the deafult.

ssh me@machine 'cmake --version'

In order to get around this, I've tried to update my /etc/ssh/sshd_config to "PermitUserEnvironment yes"

Inside my ~/.ssh/environment file I'm able to set environment variables accordingly, and update my $PATH. This works, and when running commands remotely over ssh I can see my path is updated. i.e.

ssh me@machine 'echo $PATH'

I've also created a ~/.ssh/rc file which I can confirm DOES get called. However, even though I've put the same "module load /path/to/cmake/3.x.x" I still see it loading v2. The same goes if I update and export my PATH inside my .ssh/rc. It updates, but it seems it's applying it to a different shell than the one being used remotely.

I don't understand why ~/.ssh/environment modifies things for the current shell, but ~/.ssh/rc modifies things for seemingly a different shell.

Any ideas on how I can use environment modules remotely?

Thanks

0

In my experience, certainly with RHEL and Fedora, ~/.bashrc does get run in the sort of "non-interactive" SSH connection you're referring to. I also use the modules system (on RHEL), and have no problem with modules loading from my ~/.bashrc when I execute a command via SSH.

According to the following question/answers from the UNIX/Linux StackExchange site, some distros contain code in their default .bashrc (from /etc/skel) to abort if non-interactive - could it be you have something like that in place near the top of yours? There is also discussion in there that seems to confirm that bash, when run from SSHD, will run ~/.bashrc.

https://unix.stackexchange.com/questions/257571/why-does-bashrc-check-whether-the-current-shell-is-interactive

  • Are you asking a question or writing an answer? If your intention was to leave a comment regarding the inquiry, read over "Why do I need 50 reputation to comment" when you get a chance to ensure you understand how you can start commenting. – Pimp Juice IT Jul 31 '17 at 12:30
  • @Stingray: Yeah, it definitely isn't calling either my ~/.bashrc or /etc/bashrc, which is why I was trying to go this route instead. I'm using RHEL 6.9. – Jordan Jul 31 '17 at 17:51
  • RHEL6.9 here too, and if I run "ssh x@y cmd", then my ~/.bashrc definitely gets run on the remote system. It's also the same on RHEL4/5/7 for me. Strange, I wonder what's different in your environment. – Stingray Jul 31 '17 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.