27

Possible Duplicate:
Why does an SSH remote command get fewer environment variables then when run manually?

If I put command

ssh user@$IP ant

then I receive

bash: ant: command not found

but when I log into

ssh user@$IP

and put

ant

then work fine.

Ant is installed on remote and local machines. Where is the problem?

I've tried to find solution in google and found nothing.

Thanks in advance for help!

--EDIT--

I need to invoke some bash scripts, don't want to change all paths to full path.

Community
  • 1
  • 1
Marek Bardoński
  • 529
  • 1
  • 5
  • 14

2 Answers2

19

By default profiles aren't loaded when connecting via ssh. To enable this behaviour, set the following option in /etc/ssh/sshd_config:

PermitUserEnvironment yes

afterward restart ssh

/etc/init.d/ssh restart
Chris Montanaro
  • 16,948
  • 4
  • 20
  • 29
  • 5
    `PermitUserEnvironment` doesn't control whether the user's profile runs on the server. It only controls whether environment settings in certain server-side configuration files are honored. That's not relevant to the usual cause of the OP's problem. – Kenster May 25 '16 at 18:16
  • 1
    Perfect answer :) – ZenithS Aug 26 '19 at 06:57
  • @ZenithS, it's only perfect if the _local_ system with the SSH **client** has the environment variables you need. If the environment variables are in the dotfiles on the SSH _server_ side, it does no good whatsoever. (I came here via someone asking a new question after this answer failed to solve their problem). – Charles Duffy Oct 17 '22 at 17:37
15

Specify the absolute path to ant, if I recall correctly your profile doesn't get run when you run a remote ssh command.

Benj
  • 31,668
  • 17
  • 78
  • 127
  • This fixed the issue of finding the command, but now it can't find the shared libraries: `error while loading shared libraries: libASC_LibTools.so: cannot open shared object file: No such file or directory` – Katie Mar 01 '18 at 22:22
  • the real answer imo. But is there a way to run the profile so I can use the command alone without the absolute path? – Simon Jan 08 '19 at 16:40