maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   Enable/Disable ssh server depending on wifi connection (https://talk.maemo.org/showthread.php?t=65061)

colder 2010-11-04 15:52

Enable/Disable ssh server depending on wifi connection
 
hey guys, I have a small question and I'm hoping someone can help me....

I do not know how much battery ssh server consumes but since some people opened a couple of threads I guess it may play a significant role in its duration.

I was thinking of finding a way to boot the n900 with the ssh server stopped and then have it started only when I connect to the internet and stopped again when I disconnect.

I do not know if this could be possible, I am not a guru on that stuff, but what if we could put 2 scripts in

/etc/network/if-up.d and
/etc/network/if-down.d
respectively.


Would this work?

Thanks in advance

aligatro 2010-11-04 16:13

Re: Enable/Disable ssh server depending on wifi connection
 
Should work. Try it
put

into /etc/network/if-down.d

#!/bin/sh
/etc/init.d/sshd stop

into /etc/network/if-up.d

#!/bin/sh
/etc/init.d/sshd start

[added]remove sudo
[added] ok it doesn't work. :S

ToJa92 2010-11-04 16:30

Re: Enable/Disable ssh server depending on wifi connection
 
Otherwise there's a statusbar applet which let you stop/start the SSH server. Can't remember its name.

colder 2010-11-04 16:45

Re: Enable/Disable ssh server depending on wifi connection
 
Thanks! I'll give it a try later today and post the results!

BTW: Will sudo work? Shouldn't I just create the file as root?

noobmonkey 2010-11-04 16:49

Re: Enable/Disable ssh server depending on wifi connection
 
oo interested in this for a few ways!
After a reboot i always forget to turn it back on! doh - and on connecting to wifi it would be great!
Also - how much power would it being on actually use? (Or more realistically does it poll something? if so how often etc...)

cddiede 2010-11-04 16:52

Re: Enable/Disable ssh server depending on wifi connection
 
I use the following upstart script to start a new VNC server everytime a new network connection is started. It dosen't deliniate between Wi-Fi and GPRS/3G, but it may be useful:

I've placed the following script (called vncs) in:

/etc/network/if-up.d

What this does is first off, starts a vnc server on the N900 whenever a network connection is established.

Secondly, it will kill any vnc server that is already running so you don't end up with a boatload of vnc server processes running if you connect to several networks throughout the day.

script follows:

APPCHK=$(ps aux | grep -c x11vnc)

if [ $APPCHK = '0' ];

then

/usr/bin/nohup /usr/bin/x11vnc -forever &

else

/usr/bin/pkill x11vnc;/usr/bin/nohup /usr/bin/x11vnc -forever &

fi

aligatro 2010-11-04 17:10

Re: Enable/Disable ssh server depending on wifi connection
 
Quote:

Originally Posted by colder (Post 863414)
Thanks! I'll give it a try later today and post the results!

BTW: Will sudo work? Shouldn't I just create the file as root?

o yea. ignore the sudo. It's used on ubuntu, because root account is inactive.

javispedro 2010-11-04 17:25

Re: Enable/Disable ssh server depending on wifi connection
 
I personally use http://en.wikipedia.org/wiki/Inetd to launch the SSH server.

A bit harder to setup, introduces latency when connecting to it, but you need only one daemon active that _for sure_ does not use any extra CPU time. You can also use it to launch VNC server, Samba server....

OTH I'd be wary that the openssh server uses any battery, specially without a network connection. The reason I use inetd is because I run some other services that are "less tested".

colder 2010-11-06 20:53

Re: Enable/Disable ssh server depending on wifi connection
 
@cddiede
That's exactly what I want to end up doing, only I wanna tunnel vnc through ssh. I will try to modify your script sometime this weekend.

What I want to end up doing is create a script that, when connected, will update my dyndns.org account with the current ip and start openssh server. In the same manner, when disconnected, it will shut down openssh server for power saving.

This way I can remotely connect to the phone whenever it is connected through wifi. Another advantage (if this works right), is that it can help as a WEAK anti-theft solution; if someone steals the phone and just changes the sim card without formatting, it may be useful in recovering it.

Right?

bobbydoedoe 2010-11-07 04:59

Re: Enable/Disable ssh server depending on wifi connection
 
i am quite interesting in this script to disable/enable the ssh depending on wifi connectivity. any updates to this thread?

colder 2010-11-07 20:03

Re: Enable/Disable ssh server depending on wifi connection
 
Ok, here's what I've done so far:

Code:

sudo gainroot
(you need to have the gainroot package installed)

edit /etc/event.d/sshd

I used "vi" to do that.

Comment out the first line:
Code:

#start on stopped rcS
and reboot. This way, ssh server will not autostart on boot.

Next step, give a password to "user"
Code:

sudo gainroot
passwd user

Then, edit /etc/ssh/sshd_config
Added the lines
Code:

AllowUsers user
MaxAuthTries 5

and changed
Code:

PermitRootLogin no
Port xxxx

where xxxx is a port of your choice, if you want other than 22

I have to leave home now, but I think two simple scripts in /etc/network/if-up.d and /etc/network/if-down.d should do the job:

start_ssh in /etc/network/if-up.d:
Code:

#!bin/sh
sh /etc/init.d/ssh start

stop_ssh in /etc/network/if-down.d:
Code:

#!bin/sh
sh /etc/init.d/ssh stop

I will hopefully try it later today as soon as I get home and then move on to configuring dyndns with the current ip.


Noob Question: If you have a device "A" connected to a public wifi (coffee shop, friends house), is there any way to ssh from device "B" into "A" without having to set modem port forwarding?

E.g.: if "A" is configured to listen to port 1234 and we know "A"'s public ip, will this work without configuring the modem(assuming 1234 is open)?

Code:

ssh -p 1234 user@publicIP
Never tried it before without port forwarding....

colder 2010-11-08 02:14

Re: Enable/Disable ssh server depending on wifi connection
 
For some reason it does not seem to work. Here's the start script:

Code:

#!/bin/sh

cd /root/ipcheck
python ipcheck.py -l -r checkip.dyndns.org:8245 username password domain
/etc/init.d/ssh start

where username/password/domain are the credentials for dyndns.org

and then
Code:

chmod 755 start_script.sh
I tried connecting and disconnecting the internet connection a few times but the script does not seem to run. I even added something silly such as

Code:

mkdir /home/user/test
for testing purposes but it does not get executed at all.

Any ideas?

colder 2010-11-08 02:27

Re: Enable/Disable ssh server depending on wifi connection
 
NAILED IT!

On the above script, I replaced

Code:

#!/bin/sh
with
Code:

#!/bin/ash
and also renamed the file from start_script.sh to start_script (won't work otherwise)

Don't know what made the difference, I was just experimenting....

:D


All times are GMT. The time now is 11:43.

vBulletin® Version 3.8.8