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-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