Running bash via ssh shows error: /usr/bin/env: bash: No such file or directory

Here is my

#!/usr/bin/env bash
echo succeed

When I direct run it, it output:

[jerry@Jerry-DELL ~]$ ./

However, when i run it through ssh:

[jerry@Jerry-DELL ~]$ ssh localhost /home/jerry/
/usr/bin/env: 'bash': No such file or directory

Then, when i change “/usr/bin/env bash” to “/bin/bash”, it works:

[jerry@Jerry-DELL ~]$ ssh localhost /home/jerry/

So, what’s the problem? How can i fix it? By the way, i use openssh8.6.

From what I read using that makes the shell itself search for bash in $PATH, when directly pointing to the executable will simply use the executable. So maybe from SSH there is an issue with $PATH.

1 Like