简体   繁体   English

用于sudo访问的ssh环境变量

[英]ssh environment variable for sudo access

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..) 如果我想通过ssh连接启动一些命令,我​​在那里提供带变量的〜/ .ssh / environment文件(但它不允许我在那里使用bash命令..)

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 但是如果我想用sudo启动一些命令(例如sudo java ),通常我会将以下行放到我的.bashrc文件中

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. 所以,我不能把这个别名放到我的〜/ .ssh / environment文件中,因为它不支持任何命令。

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. 只是提醒问题是: 如何调用[sudo + command]考虑到* sudo ssh有一些限制才能看到环境变量。 * (see above in the question). *(见上文问题)。

So we may use sudo like this: 所以我们可以像这样使用sudo:

 sudo env PATH=$PATH command

It will pass PATH variable into sudo context. 它会将PATH变量传递给sudo上下文。

It was not obvious for me that we can use something different just after sudo.. not command but env 对我来说,在sudo之后我们可以使用不同的东西并不是很明显..不是命令而是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) 在./.ssh/environment(ssh策略限制 - 它不允许它),我们不能在.bashrc中使用它(ssh策略限制 - 它不使用它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM