Reply
Thread Tools
Posts: 92 | Thanked: 9 times | Joined on Nov 2009 @ Germany, Bavaria
#1
Hi!

I use a NSLU2 (NAS-System) which runs linux (debian) with a usb-controlled multiple power socket (Gembird) to control the light in my living-room. Works fine. (At this time I control it with a PHP-based webpage on the NSLU)

Now i want to switch the sockets without this (slow) webpage.
My idea was to create a script which connects via SSH from the N900 to the NSLU and then run the needed commands.

When i connect manually with XTerminal over SSH i get a prompt to enter my password. After this i can run the command.

How can i put this in a script? Is this automation possible with a "password-based-authentication?". Or do i need certificates or something like this for authentication.

My second question: How can is put a link to this script to my "program menu" or to a homescreen.

Thank you!

Last edited by RouterRebooter; 2010-01-06 at 18:01.
 
Posts: 287 | Thanked: 127 times | Joined on Oct 2009 @ Sweden
#2
For logging in, use public key authentication (google is your friend). It really isn't hard to setup, create a pair of keys and put the public one on server and the private one on the device, plus change a line in the server config.

For executing a command upon login, just use ssh user@host command (so you can create a script on the N900 that logs on to the nslu2 and runs a script to toggle the lights).
 

The Following User Says Thank You to floffe For This Useful Post:
Posts: 92 | Thanked: 9 times | Joined on Nov 2009 @ Germany, Bavaria
#3
Thanks for your fast response!

Sounds manageable to use public key authentication. I'll try it!

Do you know wheter it's complicated to add an shortcut or something to the homescreen / menu?
 
Posts: 207 | Thanked: 119 times | Joined on Nov 2009 @ Pittsburgh, PA, USA
#4
RouterRebooter: Think about n900 like about normal linux machine.

here it is: http://rcsg-gsir.imsb-dsgi.nrc-cnrc....et/node31.html

after this you can use command like this:
ssh username@IPofMachine Commands for execution....

If you need step by step instruction, I can write it in 2 hours (now don't have time)....
 

The Following User Says Thank You to mikhmv For This Useful Post:
brendan's Avatar
Posts: 531 | Thanked: 79 times | Joined on Oct 2006 @ This side of insane, that side of genius
#5
Originally Posted by mikhmv View Post
ssh username@IPofMachine Commands for execution....
this assumes that the "Commands for execution" reside on the remote machine.
__________________
Nokia n800
OS 2008
Pharos iGPS 360-BT
ElmScan 5 BlueTooth
BlackBerry Bold (9000)
AT&T Wireless
 

The Following User Says Thank You to brendan For This Useful Post:
Posts: 92 | Thanked: 9 times | Joined on Nov 2009 @ Germany, Bavaria
#6
Originally Posted by mikhmv View Post
RouterRebooter: Think about n900 like about normal linux machine.
Easier said than done I don't have any linux machines (except the NAS-System which i only use for light-control). I'm a linux newbie

I'm pleased about your helpfulness - really great!

I'll try to establish the connection with the method form your link. If I've further questions, i put it in this thread

Thanks!

Does anyone know how it's possible to add an shortcut (to run the script on N900) or something to the homescreen / menu?
 
Posts: 92 | Thanked: 9 times | Joined on Nov 2009 @ Germany, Bavaria
#7
Originally Posted by brendan View Post
this assumes that the "Commands for execution" reside on the remote machine.
This means that i can put the commands to a file at the remote computer (NSLU) and run it via the
"ssh username@192.168.X.X /path/commandfile.*" command?
 
Posts: 352 | Thanked: 231 times | Joined on Jul 2008 @ Vancouver
#8
Hi RouterRebooter,
The info to make a desktop icon to run an ssh command can be found in this post:
http://talk.maemo.org/showthread.php?t=35858

I used it to run WOL (an installed app on my Linux device) via SSH. the icon method allows you to run one command. but you can make a script to run many commands. the cool thing is you can also make your own icons too. i am a newbie to Linux and the terminal but with minimal experienced i achieved success. a program i found essential was WinSCP it gives you a windows GUI like file manager to you n900 after you have installed SSH Server.

I had to install a new program on my n900 and restart before my icons showed up. I now have several custom desktop icons that run SSH scripts.

good luck
tim

ps. if you read the whole post i ask all the newbie questions.

Last edited by timwatt; 2010-01-06 at 17:53.
 

The Following User Says Thank You to timwatt For This Useful Post:
Posts: 92 | Thanked: 9 times | Joined on Nov 2009 @ Germany, Bavaria
#9
Originally Posted by timwatt View Post
ps. if you read the whole post i ask all the newbie questions.
Thanks for your reply (and the edit ) !

Sounds good! Now i only need time to read and test it - I hope tomorrow
 
Posts: 207 | Thanked: 119 times | Joined on Nov 2009 @ Pittsburgh, PA, USA
#10
Step by step protocol for create passwordless connection:
1. install packages OpenSSH (client, if you want server too) and rootsh on n900.
2. open x-term
3. "sudo gainroot" (or just "root")
4. "ssh-keygen -t rsa" (create keys)
Use everything by default (press enter)
5. $ "cd .ssh" (go to folder .ssh)
6."cp id_rsa.pub N900_id_rsa.pub". it make copy key file to N900_id_rsa.pub. You can use any name. It is helpful if you have many servers.
7. "scp N900_id_rsa.pub ServerUserName@IPofServer:/PathToUserHomeOnServer/.ssh/" If you are going to connect like root it will be:
"scp N900_id_rsa.pub root@IPofServer:/root/.ssh/". you will be asked for password. it will copy your password file on server
8. "ssh ServerUserName@IPofServer". Connect on server. You will be in home folder of User
9. "cd .ssh" Go to folder .ssh. For root it will be /root/.ssh
10. "ls" Get list of files in folder. You should look for "authorized_keys" or "authorized_keys2" file. I don't know why but some servers have "authorized_keys2" file by default. It is not necessary to exist.
11. "cat N900_id_rsa.pub >> authorized_keys". this will attach text from N900_id_rsa.pub file to the end of authorized_keys. If in previous step you find file "authorized_keys2" you should use "cat N900_id_rsa.pub >> authorized_keys2".
12. "exit". Disconnect
13. "ssh ServerUserName@IPofServer" You should connect to server without password. If you asked for password that mean something wrong here.
Create script:
1. Open any text redactor which can save text "ascii" files. on n900 it could be "leafpad" (starting from menu) or "nano" and "vi"(for x-term). You should install packages before. I personally more prefer nano. But you can use windows Notepad.
2. put first line "#!/bin/sh"
3. Add all commands which you type in terminal when connected to server.
4. Save file like "ascii" for example it will have name: "commandsFile"
5. open x-terminal
6. "scp commandsFile ServerUserName@IPofServer:/usernameHomeFolder/" for root it will be "scp commandsFile root@IPofServer:/root/". this will copy you file to server. Should be without Password (if you copy from device which you used in "protocol for create passwordless connection")!!! If you use other user than root probably will be better to store this file in "/usr/bin" but it is on your choice....
7. "ssh UserName@IPofServer chmod ug+x /usernameHomeFolder/commandsFile" Make this file executable.

For running this script you should use:
"ssh UserName@IPofServer /PathToFile/commandsFile"
P.S. how to find new information for n900 you can google it! in this case: "passwordless login linux". In most of cases it will work for n900 except missing some packages. If you will need porting some packages from other distribution (like debian) you can make request for porting here, on forum. Most of packages (for command line execution) can be easily ported.
 

The Following User Says Thank You to mikhmv For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 22:54.