ssh "!command" escape sequence - does it work?

Chris Green cl at isbd.net
Fri Sep 11 14:31:03 UTC 2020


On Fri, Sep 11, 2020 at 10:58:52PM +1000, Karl Auer wrote:
> On Fri, 2020-09-11 at 13:11 +0100, Chris Green wrote:
> > Yes, as it's supposed to be.  As you say though the rest of the
> > !command escape seems to be, at the very least, not quite what one
> > expects.  I've searched around quite a bit but I've not found
> > anything very helpful.
> 
> I turned on debug with "-vvv", and:
> 
> otherhost:~$ [enter ~C] 
> ssh> !echo freddy
> debug3: Executing /bin/bash -c "echo freddy"
> [enter]
> otherhost:~$
> 
> I.e., nothing was actually echoed, but:
> 
> otherhost: ~$ /bin/bash -c "echo freddy"
> freddy
> 
> myhost: ~$ /bin/bash -c "echo freddy"
> freddy
> 
> This led me to think about what stderr and stdout might be when
> executing a program deep in the bowels of ssh.
> 
> Now watch this :-)
> 
> myhost:~$ ssh otherhost
> otherhost:~$ 
> ssh> !echo boo > /tmp/boo.txt
> 
> otherhost:~$ exit
> logout
> Connection to otherhost closed.
> myhost:~$ ls -la /tmp/boo.txt
> -rw-r--r-- 1 kauer kauer 4 Sep 11 22:47 /tmp/boo.txt
> myhost:~$ cat /tmp/boo.txt
> boo
> 
> Ta daaa!
> 
> I.e., it was working all along. I bet that, like me, you were trying to
> do something simple like local console output :-)
> 
> More investigation needed, but it makes sense not to allow you to
> scribble on the remote's stdout, though it seems happy to scribble on
> stderr.
> 
Well done Karl.  Maybe the warning about running 'interactive'
programs as LocalCommand relates to this: "It should not be used for
interactive commands".


> The code that actually does this is a function called ssh_local_cmd in
> sshconnect.c. It does a fork/exec sequence. You can get errors written
> to syslog with the ssh "-y" option.
> 
It would be helpful if it actually just said output to stdout is
blocked.

I wonder if it will allow starting a GUI program on the local system,
that's what I actually want to do (I'm reading E-Mail via ssh and want
to fire up a PDF viewer *locally* when there's a PDF attachment). I'll
try it.

-- 
Chris Green




More information about the ubuntu-users mailing list