Enable uhttpd automatically on ssh session?

Hey all,

I'm new to openWRT and so far I'm really enjoying the power of it!

As I am entertaining the idea of accessing my home network&router from outside, so I was looking into hardening my router configurations, e.g. like this https://openwrt.org/docs/guide-user/luci/luci.secure. Now the last lines and the whole SSH tunnel really gave me an idea.
What I would like to do: on a successful SSH session start, automatically start uhttpd, so I can use http(s). After the SSH session closes I would like to automatically stop and disable uhttpd. In Manjaro, one can write hooks, but seeing openwrt is a sort of "lightweight" linux (and I'm a beginner in linux as well) I am not sure as to how it can be done, if it can be done at all. As it is a little more specific, I was not able to find decent google hits for my search, but maybe people here can help me out.


Use a vpn. Much more secure than opening your routers ssh and/or web interfaces to the internet, and with a vpn you’ll have access to the router via ssh and web and your network if you want.

Take a look at wireguard

cat << "EOF" > /etc/profile.d/ssh.sh
[ -n "$SSH_TTY"  ] && [ "$USER" = "uhttpdfg"  ] && {
uhttpd -f ....


you could write a script starting and stopping (e.g. react with trap to EXIT signal) uhttpd and call it from your profile like below.

root@md-home-wifirouter:~# cat ~/.profile
if [ -n "$SSH_CONNECTION" ]; then

Solid advice here... instead of creating weird configurations, I would go for the tried and tested solutions available.