1

I joined a project which utilizes Java to execute SSH commands, I'm trying to run a test suite on localhost. Short commands are executed properly. Running longer commands is a challenge, though. An SSH command is built, it looks like this:

ssh -v username@localhost bash -c "long-command"

Where long-command is about 2000 characters in length - it contains a list of encoded values and I can't change this fact without major changes in project's architecture. In Java long-command is reflected properly and uncut as far as I can check using debugger, it's passed to ProcessBuilder. The errorlog of SSH command execution says however:

debug1: Sending command: bash -c long-command-cut-in-half

Command's length (measured starting from "bash" keyword) can only reach 900 characters. Anything past this number is lost, which makes the command invalid.

I'm using Bitvise SSH Server on Windows, ssh.exe comes from OpenSSH installed as an optional function in Windows 10 - results were the same when using ssh.exe delivered with Git - and have Cygwin installed.

The command should surely be shorter, but it doesn't exceed OS limit. I've been looking for an answer for a while: why is this happening?

stackrat
  • 31
  • 2
  • 1
    It seems like it should be relatively easy to present a [mcve]. Only that way can we judge whether there may be some characteristic of the command other than its length that is causing the failure. The next most likely alternative would be that the problem is in your ssh client, but right now we haven't really enough information to judge.. – John Bollinger May 11 '18 at 22:31
  • 1
    [Here](https://stackoverflow.com/questions/305035/how-to-use-ssh-to-run-a-shell-script-on-a-remote-machine) is a good answer to your problem. Write a bash script with your command (with proper quoting) and try. You can check the args length limit of your shell with `getconf ARG_MAX`, most probably well up from 2000. – LMC May 12 '18 at 00:33
  • 1
    **OpenSSH client does this truncation** regardless of OS(es); see `client_session2_setup` in `clientloop.c` (source linked from www.openssh.com or downloadable many places). I see no explanation and [it appears to have been added in 2004](https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/clientloop.c.diff?r1=1.122&r2=1.123&only_with_tag=MAIN). You could either patch it and build your own, or try another implementation like Tectia, Jsch or sshj. – dave_thompson_085 May 12 '18 at 03:42

0 Answers0