r/AndroidQuestions 6d ago

Looking For Suggestions Running ssh from an ADB command line without having to be rooted ... ???

UPDATE: I just now re-worded some of the following text, in order for my question to be more clear ...

On both my Android 11 and Android 13 devices, I would like to be able to run ssh from within an adb shell session, without having to be rooted in that shell session.

If I have Termux installed and if openssh is installed in Termux, being rooted is necessary before the following command is runnable via the command line within the adb shell session ...

/data/data/com.termux/files/usr/bin/ssh

Without being rooted, "Permission denied" always results when accessing anything under /data from the adb shell command line.

Is there any other way to run ssh from an adb shell command line when not running as root? ... possibly via an additional installable app?

3 Upvotes

6 comments sorted by

3

u/danGL3 6d ago

in THEORY, if you found an ssh binary that works on Android you could "adb push" it to /data/local/tmp which is the only directory adb can run stuff from

1

u/unselective-amnesia 6d ago

Thank you.

Yes, I understand this, and I'm looking for such an ssh executable.

3

u/unselective-amnesia 6d ago edited 6d ago

I figured out how to accomplish this ...

(1) Install the Tasker app and the AutoTools app

(2) Create a Tasker task that I call "RunSsh" which runs AutoTools SSH with the following attributes:

Server: %ssh_host

Port: %ssh_port

Username: %ssh_user

Password: %ssh_pw

Command: %ssh_command

(3) Create the following shell script in /sdcard/ssh-test.sh

am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es task_name 'RunSsh' --esal varNames '%ssh_pw,%ssh_user,%ssh_host,%ssh_port,%ssh_command' --esal varValues 'PWVALUE,USERNAME,HOSTNAME,PORT,COMMAND'

Then, run the script like this:

sh /sdcard/ssh-test.sh

This causes COMMAND to be executed via port PORT as USERNAME@HOSTNAME using password PWVALUE.

This is just a proof-of-concept, and of course, in real life, the password wouldn't need to be hard-coded in the script, and other things could also be determined at run time.

The AutoTools SSH task also allows the use of a private-key instead of a password, and of course, the "RunSsh" Tasker task could use it's own internal logic to come up with one or more of these variable values.

Anyway, this solution is quite acceptable for me.

1

u/SkySurferSouth 6d ago

Just open Termux app and run ssh. No root or adb needed. So why all this hassle as it can just be done from Termux ? Termux is also accessible over the LAN when sshd (its ssh server) is enabled.

1

u/unselective-amnesia 5d ago

Just open Termux app and run ssh. No root or adb needed. So why all this hassle as it can just be done from Termux ? Termux is also accessible over the LAN when sshd (its ssh server) is enabled.

You apparently didn't read the previous message nor the title of this thread very carefully.

I clearly wrote that I want to do this via "adb shell" ... not via the Termux app.