This question is another side of that question
If I want to launch some command over ssh connection, I provide ~/.ssh/environment file with variables there (but it does not allow me to use bash command there..)
But if I want to launch some command with sudo (like sudo java, for example), usually I put the following line to my .bashrc file
alias sudo='sudo env PATH=$PATH'
So, I can NOT put this alias into my ~/.ssh/environment file, because it does not support any commands.
So, what it is the best way to fix it in this case?
I found a solution.
Just remind that the issue was: how to invoke [sudo + command] taking into account that either *sudo or ssh has some limitation to able to see environment variables.* (see above in the question).
So we may use sudo like this:
sudo env PATH=$PATH command
It will pass PATH variable into sudo context.
It was not obvious for me that we can use something different just after sudo.. not command but env
And we can NOT use
alias sudo='sudo env PATH=$PATH'
in ./.ssh/environment (ssh policy limitation - it does not allow it) and we can NOT use it in .bashrc (ssh policy limitation - it does not use it)