ssh client code example for Arduino Yun?

Hi guys,

I am newbie with programming over this board... and I am wondering if there exists support for ssh client... I downloaded an external ssh C library (libssh.org) and I have been trying to compile some examples from http://api.libssh.org/master/libssh_tutor_guided_tour.html but I cannot compile that into the Arduino Yun sketches. :~

Any suggestion will be welcome, thank you in advance Sorry for my English

Regards.

Arthur.

Perhaps it would help us to know what it is you are trying to achieve?

If you're trying to compile SSH on the AVR chip then you're completely barking up the wrong tree.

Hi majenko,

Thanks you for the quick reply!

I need to send a linux shell command via ssh to a remote host (virtual machine). That command would be, for instance, a shutdown command.... Now I think about to take some alternatives... Could I use the Process class available for run a "native" C program which perform the required task: log through ssh (providing user-passwd), then execute a linux shell command ?

Regards. Arthur.

That would be the normal way to perform a complex network task on the Yun, yes.

For SSH you don't need to provide a user password. Set up a public/private key pair. Have the private key stored on the Yun, and the public key authorized on the server, and ssh should be able to connect without requiring a password.

This could help: https://www.debian.org/devel/passwordlessssh

Thanks you so much, majenko!

I wrote a test code using libssh and I could perform the task: the sending of shell command for shutdown a remote machine. But I wondering if is it possible to run that code through... Process.runShellComand("shutdown_remote_machine"); where "shutdown_remote_machine" is the C binary source which executes that task... Can I add this binary source code from "Add file..." in Sketch tab of Arduino IDE? How can I access it from the sketch code .ino?

Regards.

Arthur.

Plan B:

Use sshpass; -

sshpass -p "YOUR_PASSWORD" ssh YOUR_USERNAME@SOME_SITE.COM "ls -al"
total 20
drwxr-xr-x  2 sonnyyu sonnyyu 4096 2014-07-09 10:54 .
drwxr-xr-x 13 root    root    4096 2014-07-09 10:54 ..
-rw-r--r--  1 sonnyyu sonnyyu  220 2014-07-09 10:54 .bash_logout
-rw-r--r--  1 sonnyyu sonnyyu 3116 2014-07-09 10:54 .bashrc
-rw-r--r--  1 sonnyyu sonnyyu  675 2014-07-09 10:54 .profile

download sshpass from here http://colocrossing.dl.sourceforge.net/project/sshpass/sshpass/1.05/sshpass-1.05.tar.gz

native or cross compile, package is small and native compile ( compile it at Yun) , and took less than 1 min.

Hi sonnyyu,

Thanks you for share your knowledge! I see this Plan B like a good alternative... but I am so newbie and I wonder how must I install and compile this package into my Arduino Yun? Do I need access to the Arduino Yun console and install/compile this package? Then I will be available to write your example in the sketch .ino Is it ok?

Sorry for my English :~

Regards.

Artur.

Plan C:

ssh username@foo.bar.com

add foo.bar.com into host file

opkg update
opkg install empty
nano /mnt/sda1/autossh.sh
#!/bin/sh
empty -f -i in -o out ssh username@foo.bar.com
#empty -w -i out -o in "ogin:" "root\n"
empty -w -i out -o in "assword:" "TopSecret\n"
#empty -s -o in "who am i\n"
empty -s -o in "touch newfile\n"
empty -s -o in "exit\n"
chmod 755 /mnt/sda1/autossh.sh
/mnt/sda1/autossh.sh

ssh into server foo.bar.com make sure at home directory of username, the file name of newfile is created.

http://empty.sourceforge.net/

arrudeboy: ... Do I need access to the Arduino Yun console and install/compile this package? ...

Yes. follow this one.

http://arduino.cc/en/Tutorial/LinuxCLI

Thanks you so much sonnyyu,

I've followed your guide to setup/run empty and all was well until...

when I run my script with "empty" lines I get two times the same error:

Fatal open FIFO for writing: in: No such file or directory Fatal open FIFO for writing: in: No such file or directory

This is my sh script:

autossh.sh

#!/bin/sh

empty -f -i in -o out ssh arturo@rudeboy 
empty -w -i out -o in "assword:" "654321\n" 
empty -s -o in "touch newfile\n"
empty -s -o in "exit\n"

Regards.

Arthur.

empty -s -o in "touch newfile\n"
empty -s -o in "/usr/bin/touch /home/arturo/newfile\n"

use absolute path.

I am getting the same error... :(

I am thinking to take your Plan B... Now I downloaded sshpass doing wget http://colocrossing.dl/ .... but when I try to ungzip the tar.gz file nothing occurs... the command line stays waiting...

Thanks anyway

Regards.

Arthur.

at console run ssh arturo@rudeboy

/usr/bin/touch /home/arturo/newfile

testing it again

./autossh.sh

Appendix of Plan B:

ssh YOUR_USERNAME@SOME_SITE.COM

add SOME_SITE.COM into host file.

cd /bin 
wget https://www.dropbox.com/s/bl6vyhd5jpim6zm/sshpass --no-check-certificate
chmod 755 sshpass

Download prebuild sshpass ( Proud build in Yun! ).

sshpass -p "YOUR_PASSWORD" ssh YOUR_USERNAME@SOME_SITE.COM "ls -al"

arrudeboy: ... I am thinking to take your Plan B... Now I downloaded sshpass doing wget http://colocrossing.dl/ .... but when I try to ungzip the tar.gz file nothing occurs... the command line stays waiting... ...

The tar comes with Yun is from busybox's shrink down version. Upgrade full version tar.

opkg update
opkg install tar
tar -zxvf sshpass-1.05.tar.gz

Thank you so much sonnyyu !

It was enough with following the Plan C... I would could sending the shutdown/reboot command to remote machine and it is done perfectly

Now I have to do that with a virtual machine which is the host that emulates a cluster central node... I did set up port forwarding between the host and guest... but I cannot accomplish the ssh sending command via "empty"... perhaps I need to add new port forwarding between ip:port of Arduino Yun and ip:port of virtual machine...

But I am thinking about the Plan B into the Plan C... lol wow It is very abstract !

Thanks again sonnyyu, your support was wonderful.

Regards.

Arthur.

BTW.

The majenko’s Plan A is only kosher way to get job done, since shutdown/reboot is required root access right, the password is not very safe to hardcode.

Plan A:

Detail step;-

http://forum.arduino.cc/index.php?topic=278088.msg1966615#msg1966615