ssh environment variable for sudo access

时光总嘲笑我的痴心妄想 提交于 2019-12-23 05:51:07

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/8080866/ssh-environment-variable-for-sudo-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!