1

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?

5
  • This post may help: serverfault.com/questions/109474/… Commented Nov 10, 2011 at 14:23
  • I guess it works but not for sudo & ubuntu. Commented Nov 10, 2011 at 14:31
  • Are you wanting a single approach that works for both sudo and ssh? Commented Nov 10, 2011 at 14:33
  • Yes. Or some workaround for this particular problem. for sudo I know the solution for ssh I know, but it does not help me for this problem. I've added new tag 'ssh' for that. Commented Nov 10, 2011 at 14:34
  • I'm not clear on what the particular problem is. You say you want to launch some command over an ssh connection. It seems like you want to pass a particular environment variable to the remote command. You gave an example of how you do it with sudo, but it seems like you weren't sure about how to do it with ssh. The link I posted talked about how to do it with ssh, but you say it doesn't work with sudo, so I'm confused. Commented Nov 10, 2011 at 14:41

1 Answer 1

4

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.