25

I of course have ConnectBot, but I'm looking for something I can script.

Edit: To clarify here, I'm not interested in running scripts from a terminal. What I want to do is run an SSH command in an automated/scheduled manner. Tasker and Locale Execute are the equivalent of cron, all I need is the 'ssh' command to run from the script.

1

12 Answers 12

13

You can install the Terminal Emulator from google. Alternatively there is the Better Terminal Emulator Pro. I tried the Terminal Emulator on a non-rooted phone and it seemed to work fine.

Better Terminal Emulator Pro includes the dropbear ssh client, which can be launched from the command line or via a launcher. More info from the authors.

5
  • Terminal Emulator force-closes consistently on my device, and apparently on lots of other peoples' devices. I also don't see any indication that it can be run from Tasker, or from the command line.
    – TREE
    Commented Sep 22, 2010 at 12:22
  • Turns out that Better Terminal Emulator Pro does include the dropbear client binary. Update your answer to include that info, and I'll accept it.
    – TREE
    Commented Sep 23, 2010 at 12:34
  • 1
    Ideally, you should never use closed source software like Better Terminal Emulator Pro for anything cryptography related. I'd recommend building dropbear ssh directly from source using the Cyanogen people's instructions, that's probably all BTEP did. Commented May 27, 2012 at 21:18
  • 1
    There are various open source android applications that install their own dropbear ssh client copy too, simply adding a symlink makes it work under Google's Terminal Emulator. Commented May 27, 2012 at 21:21
  • your link for terminal emulator from google androlib.com/android.application.com-android-term-jpAz.aspx says "This application seems to be removed from the Android Market" I see no 'terminal emulator' by google in google play store. The first result in the google play store is Android terminal emulator by jack palevich but it has no ssh.
    – barlop
    Commented Sep 3, 2014 at 11:40
17

Since my original question was about an ssh binary, and there is an answer for that, I'll accept that answer. However, there is another way to do what I wanted to do, kinda, that might be interesting to someone some day.

Tasker + ConnectBot can be used to execute arbitrary remote (or local, I guess, but Locale Execute is better for that) commands on a schedule.

Step 1: Set up your connection in ConnectBot.

  • You can have duplicate connections in ConnectBot as long as they have different aliases. You have to rename one first (away from user@host) in order to create the second. Long Press and select "Edit Host" to perform these changes.
  • You probably want to set up an ssh key without a password so that you can use this for automation.
  • Once the connection actually works, you can use "Post-login automation" to add the remote commands you would like to run. Make sure there is a blank line at the end so that enter is sent after your last command. Use enter or ; to separate commands. I suggest using something like "echo hello" as a test until you are sure things are working, and "exit" at the end if you don't want to leave the connection open.
  • Test this in isolation.

Step 2: Create a Tasker Task to call connectbot.

  • Create a new Task in Tasker.
  • Add an Action. From Misc, select "Action Intent"
  • The fields are:
    • Action: android.intent.action.VIEW
    • Cat: Default
    • Data: ssh url, in the form of "ssh://user@host/#alias" (without the quotes). The alias, user and host here must match the alias you set up in Step 1.
    • Target: Activity
    • Click Test. Connectbot should open and your commands should execute on the remote host.

Step 3: Use this Task in Tasker however you would normally.

3
  • Is there a way to define the connection programatically, i.e., via Tasker and calling intents?
    – Dang Khoa
    Commented Sep 18, 2011 at 23:37
  • I'm not sure about that. I don't recall exactly how I found the above Intent information, but it's basically a standard ssh URL. There are tools that can investigate Intents for apps, but I haven't used those.
    – TREE
    Commented Sep 19, 2011 at 20:35
  • I can add that if you remove the defaults for ConnectBot and have another ssh client installed (BTEP, for example) then ssh URLs will prompt for which app to use. This underscores that the above is something of a standard, both "VIEW" and the ssh format. The only thing specific to ConnectBot in this case is the #alias on the end.
    – TREE
    Commented Sep 19, 2011 at 20:37
5

I know it's an old thread but wanted to +1 the comment about BTEP

I'm also using BTEP's ssh binary though I just call it from it's path instead of linking it /data/data/com.magicandroidapps.bettertermpro/bin/ssh [email protected]

or generate a pair of keys and use public key authentication /data/data/com.magicandroidapps.bettertermpro/bin/ssh -i /data/data/com.magicandroidapps.bettertermpro/home/.ssh/id_rsa -l root 192.168.1.1

I use the above command from SL4A r4 in various scripts and it works fine :)

before I could do this I needed to chmod a+x /data/data/com.magicandroidapps.bettertermpro/home/.ssh

once this is done and you backup/restore BTEP with TitaniumBackup the permissions are kept this means if you flash a new rom you can just restore the apps and all your scripts will work again

5

I have successfully used BotBrew Basil Experimental when running Android 4.4. BotBrew Basil Experimental is based on apt-get so after installing APK and bootstraping I just did apt-get install dropbear in a root shell to install SSH client (and server).

3

Install terminal emulator and quickssh. Quickssh also includes dropbear. Does not cost you money, which it should not because this is surpassingly simple and it's based on dropbear.

https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid

find -name ssh user@host

Problem solved

1
  • 1
    looking at that program(sshdroid by beserker) I see only an ssh server gui. I then tried terminal emulator by jack, but see no ssh command added. And looking for quickssh, in the play store, I don't see it. I see only quicksshd(by teslacoil) which has a small price and no doubt isn't an ssh client.
    – barlop
    Commented Sep 3, 2014 at 12:31
2

Terminal Emulator absolutely supports scripts*. Don't believe the nay-sayers. You will need to learn BASH shell scripting, if you're not already familiar with it. Write a script and save it on your SD card. Run it with "sh filename" from Term.

If you clarify what it is you want to "script" having to do with SSH, I can likely give you a better recommendation.

*(It's actually the Android OS that supports BASH scripts, Terminal Emulator just grants you access to the Android shell, therefore scripting is inherently possible)

2
  • Updated the question. I don't want to call scripts with ssh, I want to call ssh from a script.
    – TREE
    Commented Sep 23, 2010 at 12:49
  • Exactly what I was getting at. Again, if you want to give some specifics I may be of more assistance.
    – ch3mi0n
    Commented Sep 24, 2010 at 4:00
2

To call ssh from a script, all you need to do is set up ssh keys. There are a million how-tos on the web, but there's a page on the Cyanogen wiki that might be more suited to Android users. Once you set up keys, your general ssh command would look something like this: ssh -i /PATH/TO/KEY USER@IP

You can put that in a script, run it, and you will be logged in to the remote machine.

But here's what I think you're wanting to do. To only execute a command on a remote computer, just add it in single quotes: ssh -i /PATH/TO/KEY USER@IP 'command'

That executes the command on the remote machine without logging you in. You can run commands with options, pipes, redirects etc, but it's sometimes better to keep them simple. Except for the delay, it looks the same as executing the command(s) locally and can be used the same.

Locale Execute can be picky about what commands it will run. If it doesn't work, try putting it in a script and using Locale Execute to run the script.

Also, I have had problems with the ssh binary that is on the phone and found that moving it from /system/xbin and creating a link at /system/xbin/ssh to the Better Terminal Emulator ssh binary is more reliable. The BTEP binary is in /data/data/com.magicandroidapps.bettertermpro/bin/ssh

2

Botbrew is a package manager for Android, in the likes of okpg for BSD or more recently, like APT for Debian. Pretty nice. It doesn't have an ssh client as a package, but it doesn't look too hard to put in if you're used to building your own packages. And it could be useful as a toolchain for when you want to build other C/C++/etc binaries and libraries.

So albeit this isn't a direct answer, it may be useful for some people to know about.

3
2

Now there is a terminal called Termux that you can apt install openssh in. Available on Google Play Store, F-Droid, and Github.

1
  • please link the app from Google play
    – beeshyams
    Commented Apr 23, 2016 at 10:53
-1

AndFTP can connect over any port you configure so I'm sure it could connect over SSH. But I'm not sure how easy it is to script usage of it. I use the app myself all the time for my hosting server and it works great.

Not sure if you can SSH with Terminal Emulator, but you could try it too. I use that app frequently for doing things I'm too lazy to do with ADB.

2
  • AndFTP is great. Is Terminal Emulator scriptable?
    – TREE
    Commented Sep 21, 2010 at 18:36
  • I don't think so, not without another app. As you mention above, Tasker is probably the way to go with this.
    – Webs
    Commented Sep 21, 2010 at 18:56
-1

Use an ssh plugin for Tasker? Don't need root or ssh binary then.

2
  • 7
    Name one? Your answer could be helpful then :)
    – Izzy
    Commented Apr 3, 2013 at 17:43
  • There is "SSH Plugin Paid" for Tasker, but it is old and not anymore developed. The error handling is nearly not existing, so it is just ssh and not much more. But it works.
    – franc
    Commented Dec 11, 2018 at 13:18
-3

If the simple ssh client is interesting to you, I made under Android-NDK Bionic library drobpear-ssh-client-only. ftp://ftp.simtreas.ru/pub/my/dropbear/dropbear-ssh-only.tgz sourse and ftp://ftp.simtreas.ru/pub/my/dropbear/ssh binary

1
  • This is not a generic answer sadly and will work only on one of x86/ARM/MIPS, probably ARM. Also the linked content will most probably disappear at some time. Most custom ROMs already include a working pure cmdline ssh client.
    – ce4
    Commented Sep 13, 2012 at 12:01

You must log in to answer this question.

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