If I execute the following shell command locally, I get the expected result:

adb -s 123456789 shell "su -c 'mount -o remount,rw /system;rm -r /system/app/MyApp.apk;cp /sdcard/MyApp.apk /system/app/MyApp.apk;chmod 644 /system/app/MyApp.apk;'"

Basically, adb is the Android Debug Bridge and I use it to open a shell on device 123456789. The outer set of " " is used to encapsulate the commands that must be executed in the shell. The inner set of ' ' is used to encapsulate the set of commands that must be executed as a super user on she shell. All of this works properly, and I get the expected result.

However if I try to execute this command through ssh:

ssh -i <path to rsa id file> root@<address> adb -s 123456789 shell "su -c 'mount -o remount,rw /system;rm -r /system/app/MyApp.apk;cp /sdcard/MyApp.apk /system/app/MyApp.apk;chmod 644 /system/app/MyApp.apk;'"

The commands don't get parsed correctly, and I get the following errors:

Usage: su [options] [--] [-] [LOGIN] [--] [args...]

 --daemon                      start the su daemon agent
 -c, --command COMMAND         pass COMMAND to the invoked shell
 -h, --help                    display this help message and exit
 -, -l, --login                pretend the shell to be a login shell
 -m, -p,
 --preserve-environment        do not change environment variables
 -s, --shell SHELL             use SHELL instead of the default /system/bin/sh
 -u                            display the multiuser mode and exit
 -v, --version                 display version number and exit
 -V                            display version code and exit,
                               this is used almost exclusively by Superuser.apk

mount: can't find /data in /etc/fstab
rm: cannot remove '/system/app/MyApp.apk': No such file or directory
cp: cannot stat '/sdcard/MyApp.apk': No such file or directory
chmod: cannot access '/system/app/MyApp.apk': No such file or directory

Which leads me to believe that the commands do not get parsed correctly. I tried encapsulating the ssh'd command like this, but it didn't work (I tried with single and double quotes):

ssh -i <path to rsa id file> root@<address> "adb -s 123456789 shell "su -c 'mount -o remount,rw /system;rm -r /system/app/MyApp.apk;cp /sdcard/MyApp.apk /system/app/MyApp.apk;chmod 644 /system/app/MyApp.apk;'""

I'm not a big Linux user and I tried searching around but I came up with nothing. Is there a way to execute my command through ssh?


I seem to have pin-pointed the problem. If I execute this simple command everything works perfectly:

ssh root@<address> adb shell "su -c 'ls -l'"

If I execute two commands with no parameters, I also get the expected output:

ssh root@<address> adb shell "su -c 'ls;ls'"

However, if I execute the two commands and if both commands have an additional parameter, I get an error:

ssh root@<address> adb shell "su -c 'ls -l;ls -l'"

The first command runs correctly (I get a list with the -l parameter), but instead of getting the list of files a second time I get the /system/bin/sh: ls -l: not found message. What is going on? This should be simpler to troubleshoot than my first post which had long, specific commands with multiple nested quotes.

  • In bash, you need to provide the -c switch to run commands provided in a string. May be there is such a switch in your shell as well.
    – Ketan
    Sep 24, 2014 at 0:42

1 Answer 1


I think the problem is that bash on your local machine is interpreting the quotes and not sending them along. Try escaping the quotes with \, ie \". You may have to experiment. Remotely executing commands that require quoting is always tricky.

This may not be possible in your environment, but if you can create that long command into a shell script on the remote machine and then call that script, it may save you some headache.

  • Well, if I replace the ssh with echo, I get -i <path to rsa file> root@<address> adb shell "su -c 'ls -l;ls -l'". This is the command that works if I enter it on the PC directly after connecting to it through ssh. I simply cannot get the thing to work as a 1 liner for some reason.
    – Andrew Mpy
    Sep 24, 2014 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .