ssh环境变量用于sudo访问 [英] ssh environment variable for sudo access

查看:173
本文介绍了ssh环境变量用于sudo访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是问题

如果我想通过ssh连接启动一些命令,我​​在〜/ .ssh / environment文件中提供了变量(但是不允许我使用bash命令那么..)

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..)

但是,如果我想通过 sudo (如 sudo java )启动一些命令,例如),通常我将以下行放入我的 .bashrc 文件

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'

所以,我可以将这个别名我的〜/ .ssh /环境文件,因为它不支持任何命令。

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?

推荐答案

我找到了一个解决方案。
只要提醒问题是:如何调用[sudo +命令],考虑到* sudo ssh 有一些限制,可以看到环境变量 *(见上面的问题)。

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).

所以我们可以这样使用sudo:

So we may use sudo like this:

 sudo env PATH=$PATH command

它会将PATH变量传递到sudo上下文中。

It will pass PATH variable into sudo context.

对于我来说,我们可以在sudo之后使用不同的东西..不是命令,而是env

It was not obvious for me that we can use something different just after sudo.. not command but env

我们不能使用

alias sudo='sudo env PATH=$PATH'

不能使用它在.bashrc(ssh策略限制 - 它不使用它)

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环境变量用于sudo访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆