0

I am trying to execute a remote script on a server via SSH. Simple enough. I can do it through interactive SSH:

ssh username@host
pipenv install

And this works just fine. However, when I try to run the command all at once:

ssh username@host "pipenv install"

I get the following error:

pipenv: command not found

Why on earth might this be the case? My first thought was that I was getting dropped into a different shell (like sh), but running ssh username@host 'echo $SHELL' gives me the result of /bin/bash, which is exactly the same that I get via interactive ssh. What might be going on here? I was under the impression that interactive ssh was identical to non-interactive ssh.

Jordan
  • 33
  • 1
  • 6
  • One starts an interactive shell, one runs a noninteractive shell. Noninteractive shells don't run dotfiles (with the exception of any file named in the `ENV` environment variable in strictly POSIX-y shells, or `BASH_ENV` when bash is not running in POSIX compatibility mode). – Charles Duffy Oct 17 '22 at 16:31
  • Compare to `ssh -tt username@host <<<'pipenv install'`. Or, y'know, you can source your dotfiles (`.bash_profile` or `.bashrc`, etc as-appropriate) explicitly. – Charles Duffy Oct 17 '22 at 16:34
  • I tried following the instructions in [this post](https://stackoverflow.com/questions/10562722/command-not-found-via-ssh-with-single-command-found-after-connecting-to-termina) which seems to have identical issues, but no luck. I tried restarting the service after editing the file and rebooting the machine, neither fixed the issue. – Jordan Oct 17 '22 at 16:35
  • `PermitUserEnvironment` is about the ssh client providing environment variables to the server, not about the server running dotfiles to set environment variables locally. Two different things, unrelated to each other. – Charles Duffy Oct 17 '22 at 16:37
  • `ssh -tt username@host <<< 'pipenv install' worked great! – Jordan Oct 17 '22 at 16:38
  • 1
    So the underlying issue was that pipenv is added to PATH using a dotfile, and hence not being found, because this doesn't get sourced with a non-interactive shell? – Jordan Oct 17 '22 at 16:40
  • Yes, that's exactly right. – Charles Duffy Oct 17 '22 at 16:42
  • (using `ssh -tt` forces SSH to provide a TTY so it looks like an interactive session, and then `<<<'pipenv install'` is providing the command on stdin instead of the command line, _also_ making it look like an interactive session, so the shell runs in interactive mode and reads its dotfiles). – Charles Duffy Oct 17 '22 at 16:43

0 Answers0