I think it has more to do with how the options are getting parsed by the shell. For example, this works:
$ ssh root@server /bin/sh -c '"cd /boot && ls -l"'
This has the same issue as your command:
$ ssh root@server /bin/sh -c 'cd /boot && ls -l'
If you enable the -v
switch to ssh
you can see what's going on:
1st command:
debug1: Sending command: /bin/sh -c "cd /boot && ls -l"
2nd command:
debug1: Sending command: /bin/sh -c cd /boot && ls -l
Typically when sending commands through ssh
you have to pay special attention to the quoting and wrap quotes within quotes as the various layers strip them away. Also don't bother sending /bin/sh
.
You can do very useful thing once you understand the quoting of ssh
such as the following. This will run the command on the remote server but collect the results in a file locally on the system where you ran the ssh
command:
$ ssh root@server 'free -m' > /tmp/memory.status
or this, where you tar a directory on a remote server and create it on the local system:
$ ssh remotehost 'tar zcvf - SOURCEDIR' | cat > DESTFILE.tar.gz
References
ssh root@server /bin/sh -c "ls -l /boot"
?