0
autossh -M 10984 -v -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -R 6889:localhost:22 user@rpi.local

The above command works. The one below doesn't.

autossh -M 10984 -E /home/pi/ssh.log -v -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -R 6889:localhost:22 user@rpi.local

It says,

/usr/lib/autossh/autossh: invalid option -- 'E'`

How can I specify a log file as the SSH option when passing it to autossh?

mbtamuli
  • 697
  • 1
  • 7
  • 19

1 Answers1

1

This is a limitation of autossh. The autossh source code contains a list of command-line switches which the program accepts. The list is apparently supposed to include all of the ssh options, but it doesn't include "E":

#define OPTION_STRING "M:V1246ab:c:e:fgi:kl:m:no:p:qstvw:xyACD:F:I:MKL:NO:PR:S:TVXY"
...
/*
 * We accept all ssh args, and quietly pass them on
 * to ssh when we call it.
 */
while ((ch = getopt(argc, argv, OPTION_STRING)) != -1) {
    switch(ch) {
    case 'M':
...

It seems there are a few workarounds at present:

  1. Run autossh with standard error directed to the desired file:

    autossh -M 10984 -v -o ... user@rpi.local 2>>/some/log/file
    

    SSH instances launched from autossh should inherit the redirection.

  2. Use the ssh "-y" option to log through syslog, and have syslog write the messages where you want them to be written.
  3. Modify the autossh source code to add support for the "-E" option.
  4. Report the issue to the autossh maintainer and hope he fixes it in a later release.
Kenster
  • 23,465
  • 21
  • 80
  • 106
  • The first workaround would redirect only the errors from autossh, not the ssh process it starts. Right? – mbtamuli Nov 14 '16 at 14:58
  • When one process launches another process, normal behavior is for the new process to inherit old process's standard file handles. I don't use autossh myself, but its documentation doesn't describe doing anything special to standard error for ssh child processes, so I'd expect ssh to inherit autossh's standard error. You could try it and see what happens. – Kenster Nov 14 '16 at 15:34