When using ssh remote command, e.g.,
ssh root@ip "echo $PATH"
We will have result,
/opt/render-ssh/bin. Therefore, most remote ssh commands complains “command not found”.
However, the login shell is fine, which can be confirmed by running,
ssh root@ip "/bin/bash --login -c 'echo $PATH'"
After digging into this issue, I found that the PATH variable has been overwritten in the sshd setup scrips:
/opt/render-ssh/bin/sshd-render.sh. The main function in the script overwrites the PATH variable to
/opt/render-ssh/bin, which is then being written to the sshd config file
/opt/render-ssh/var/sshd_config.d/partials/env_vars with sshd’s
The purpose of writing environment variables of current session into a sshd config file is to preserve environment variables in the coming ssh sessions.
And resetting the PATH variable in that script seems deliberate as there is no other usage of the PATH variable after that, all commands running in that script is written in full path.
Then, what is the reason of doing so? Any workaround for this issue?
Besides, the reason why login shell has suitable PATH variable is that it reset PATH variable when loading /etc/profile.