![]() |
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 |
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 |
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.
|
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? |
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...) |
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 |
Re: Enable/Disable ssh server depending on wifi connection
Quote:
|
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". |
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? |
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?
|
Re: Enable/Disable ssh server depending on wifi connection
Ok, here's what I've done so far:
Code:
sudo gainrootedit /etc/event.d/sshd I used "vi" to do that. Comment out the first line: Code:
#start on stopped rcSNext step, give a password to "user" Code:
sudo gainrootAdded the lines Code:
AllowUsers userCode:
PermitRootLogin noI 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/shCode:
#!bin/shNoob 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 |
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/shand then Code:
chmod 755 start_script.shCode:
mkdir /home/user/testAny ideas? |
Re: Enable/Disable ssh server depending on wifi connection
NAILED IT!
On the above script, I replaced Code:
#!/bin/shCode:
#!/bin/ashDon'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