3

Testing out the SSH Match Exec feature. I have this minimal ~/.ssh/config:

Match Exec echo
   ServerAliveInterval 60

and I am running

ssh localhost

I get

Unable to execute 'echo': No such file or directory

This is true regardless of whether I use a full path or not, or using quotes whether double or single. I tried putting a fake echo script in my .ssh folder as well. I have tried multiple commands (test, nc, connect). It seems the Exec feature cannot see my path at all.

I am running WSL Debian with OpenSSH. My final goal is to test if $http_proxy is reachable in the match clause in order to automate proxy usage, but getting the above to work would be enough.

0
4

You should set the SHELL environment variable to the full path of your shell, not simply to bash or zsh.

Try:

SHELL=/bin/bash ssh user@host
1
  • Thank you, good catch! – kabanus Feb 1 '20 at 14:16
10

To invoke "match" directives, ssh actually invokes:

$SHELL -c 'command'

"$SHELL" is either the value of the SHELL environment variable or a default which is usually "/bin/sh". "command" is the command from the "match" directive. Here is the actual code that executes the command:

argv[0] = shell;
argv[1] = "-c";
argv[2] = xstrdup(cmd);
argv[3] = NULL;

execv(argv[0], argv);
error("Unable to execute '%.100s': %s", cmd, strerror(errno));

Note that execv() doesn't search any kind of path for the shell being executed, so SHELL has to be a complete pathname like "/bin/bash" or "/usr/local/bin/zsh".

If the shell had started up and then failed to run "echo", then you'd get an error from the shell. But the error that you're getting is from ssh. This implies that the problem is with invoking the shell, not with the "echo" command.

The simplest explanation is that your SHELL environment variable is invalid. It refers to a file which is missing, or it's in a directory that you can't read.

3
  • Thanks, but my SHELL variable is bash. I was looking whether SSH configuration somehow overwrites it. Both $SHELL -c echo and /bin/sh -c echo work fine. – kabanus Feb 1 '20 at 14:05
  • 5
    If your SHELL is just “bash”, that’s the problem. It should be the full path to the program, eg “/bin/bash” as in the other answer. – Kenster Feb 1 '20 at 14:21
  • 1
    Thanks, that was indeed the answer. I never really noticed the variable was relative until now. – kabanus Feb 1 '20 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.