1

I try to start some command from ssh non-interactive ssh connection. I use ant-sshexec connection for that.

In order to set everything up I used this article: http://www.raphink.info/2008/09/forcing-environment-in-ssh.html

I use ~/.ssh/environment. In order to do that, I set PermitUserEnvironment to "yes" in sshd_config and restarted sshd.

In my .ssh/environment I have this content:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/ubuntu/java/jdk1.6.0_27/bin

JAVA_HOME=/home/ubuntu/java/jdk1.6.0_27

#PATH=/home/ubuntu/java/jdk1.6.0_27/bin:$PATH

#PLAY_HOME=/home/ubuntu/play

and I have the error when try to connect using non-interactive connection:

 [sshexec] Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly (the java executable should reside at JAVA_HOME/bin/java). 

But I added the java to the path..

2 Answers 2

4

The man page for sshd(8) says this about ~/.ssh/environment:

    It can only contain empty lines, comment lines (that start with
    ‘#’), and assignment lines of the form name=value.

That is, it is not a shell script at all. You have double quotes, variable expansion and an alias definition. None of that will work. Try this:

PATH=/home/ubuntu/java/jdk1.6.0_27/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
JAVA_HOME=/home/ubuntu/java/jdk1.6.0_27
PLAY_HOME=/home/ubuntu/play

Also ensure that the permissions on the ~/.ssh/environment are as described in the man page — no group or other write permissions on the file.

If you are concerned with locking yourself out of the account with a broken environment, test by logging onto the host first and running test commands such like this:

ssh localhost 'echo $JAVA_HOME'

You can ensure that the environment variables are set as you expect them and if something goes wrong, you are still logged onto the host allowing you to reverse your changes.

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

6 Comments

if I do like this I even can not login to ssh proper way at all. It says to me by entering: that all variables unavailable. Even impossible to perform command like: ls or cd. Hopefully I have several ssh connection opened, and rolled it back.
it seems it does not allow duplicate variables there as well. like PATH=... and PATH=.. but use only one PATH - at least then possible to use general commands after the edit.
@ses: Notice in my answer I do not have a duplicate path. What duplicate are you adding, and are you still expecting $PATH to expand inside this file?
@ses: I've expanded my answer. Does this help?
it seems this ssh localhost 'echo $JAVA_HOME' works - it shows my path.. Then I do not understand what is the problem.. At least path-related problem is fixed... trying to understand why it complains..
|
-1

You used multiple environement variable for path . But don't export from command what i see.

You should do it like that way.

export PATH="A"
export PATH="$PATH:B"
export PATH="$PATH:C"

Also you can get this type of help from there. So please post it to unix.

https://unix.stackexchange.com/questions/12391/how-to-run-my-c-program-from-anywhere-within-the-system-ubuntu-10-10

Hope it helps.

2 Comments

if I put export PATH="/home/ubuntu/java/jdk1.6.0_27/bin:$PATH" then I have: exception that it can not find Java.
-1: ~/.ssh/environment is not a shell script. You do not export variables in it.

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.