this post was submitted on 30 Dec 2025
24 points (96.2% liked)

Linux

11084 readers
1048 users here now

A community for everything relating to the GNU/Linux operating system (except the memes!)

Also, check out:

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 2 years ago
MODERATORS
 

Edit/Solved: Thank you for all the great input! Both on alternative solutions and on security implications. I'm going to make a draft on how I would setup the e-mail method as securely as possible as a programming/scripting exercise, but will IRL probably end up using either some reverse tunnel/shell variant.

Edit 2: or, as a hardware solution, install an extra NIC that I expose to the opennet - thus enabling remote port forwarding - while binding all my sensitive processes/traffic to my encrypted NIC.

I cannot ssh into my Linux box from outside of my LAN since I'm behind a VPN that doesn't support port forwarding. Is it possible to make my Linux box receive, interpret and execute commands through e-mail instead? I've tried looking for answers through DuckDuckGo's search engine, to no avail. If I may dream, I would like to setup an e-mail server with a systemd service or just run a script that continuously downloads the emails, prints their content to stdin and executes, perhaps through command substitution, whatever is in stdin.

top 24 comments
sorted by: hot top controversial new old
[–] HelloRoot@lemy.lol 13 points 2 weeks ago* (last edited 2 weeks ago) (2 children)

Sounds like ~~A/B~~ X/Y problem.

If you just want to ssh into it - there is a thing that you can find by searching "reverse remote shell over HTTPS/WebSocket".

Solutions like these pop up, but I have not personally used any of them:

  • Upterm
  • WebTTY
  • sshx
  • Teleconsole
  • tmate

Check out whether they could do what you want them to do.

[–] frongt@lemmy.zip 6 points 2 weeks ago (1 children)

*xy problem. A/B is a user testing thing.

[–] HelloRoot@lemy.lol 3 points 2 weeks ago

right, right, sorry, my brain is foggy rn.

[–] vk6flab@lemmy.radio 10 points 2 weeks ago (2 children)
[–] xcjs@programming.dev 1 points 2 weeks ago

Seconded - just use Tailscale and SSH.

[–] Muffi@programming.dev 1 points 2 weeks ago

This is the best solution. Look into Tailscale, it's brilliant for your use-case.

[–] just_another_person@lemmy.world 7 points 2 weeks ago

Do you mean you're behind a NAT and can't forward maybe?

Tailscale or ZeroTier will work around that.

[–] MontyZuma@mastodontech.de 7 points 2 weeks ago (2 children)

@emotional_soup_88 possible, but sounds like an extremely bad idea. If you can send commands, then everybody else can.

[–] emotional_soup_88@programming.dev 3 points 2 weeks ago (1 children)

True. Hadn't thought of that. Maybe I could make the address extremely long and arbitrary? And "hide" it behind my e-mail alias service?

But I absolutely understand the security implications.

[–] Dekkia@this.doesnotcut.it 5 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

Security by obscurity as single line of defense is generally not a good idea.

And then there is user management and permissions that I could sprinkle on top that.

[–] Auth@lemmy.world 2 points 2 weeks ago

Yes but your script can check who the email is from and check its certs before doing any operations on it. The only security issue is the email being read in transit but that can be worked around by not sending sensitive info.

[–] dgriffith@aussie.zone 6 points 2 weeks ago (1 children)

If you can arrange a fixed IP address externally (or dynamic DNS that follows your IP around) you can set up a reverse SSH connection instead.

Basically your server connects to your external computer via SSH and then sets up port forwarding so that when you connect to localhost:2222 or similar on your PC, you're actually connecting back to the server.

[–] emotional_soup_88@programming.dev 2 points 2 weeks ago (1 children)

Now THAT sounds like a smart solution! I'll look into it! :) I can ask my ISP to give me a static address for my home. But something needs to prompt the ssh command "at home" to connect to my second computer, right (actually Termux on my Android phone)?

[–] dgriffith@aussie.zone 3 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

It can be a Cron job that runs every minute. Run a script that:

  • Checks for the existence of a file, if it exists, exit.
  • (Optional) ping your end, if it's up, continue, otherwise exit
  • Touches said file.
  • Runs SSH to try and connect to your end. If the connection is made everything halts here until the connection drops.
  • Cleans up said file.
  • Exits.

Thanks! I'll noodle it around a little. :)

[–] yaroto98@lemmy.world 6 points 2 weeks ago

Something like selfhosted Matrix might be better securitywise. Email is pretty unsecure, anyone could send an email to you with a command. But with Matrix you'd at least need a token.

Plus there are plenty of hooks/bots you can add to Matrix. NodeRed is an easy one for automations. Send a message to a channel, and it executes different automations. Can easily be a shutdown/ssh command.

There are a couple of apps on f droid that implement this with SMS.

[–] nyan@lemmy.cafe 4 points 2 weeks ago

It's possible—I've used Perl scripts to pull data automatically out of email attachments stored in a maildir setup, and you should be able to pick commands out of a plain-text email body with a scripting language even more easily—but I will add my voice to the chorus that's saying you should look into any other method you can find before settling on this. If it turns out you must proceed along these lines, think long and hard about security.

[–] illusionist@lemmy.zip 4 points 2 weeks ago (1 children)

I'll check it out.

[–] brickfrog@lemmy.dbzer0.com 2 points 2 weeks ago* (last edited 2 weeks ago)

I've never needed to do this but have you looked into creating a Reverse SSH Tunnel? Maybe that can accomplish what you want https://www.howtogeek.com/428413/what-is-reverse-ssh-tunneling-and-how-to-use-it/

Similar to what you are trying to do - A while back when I needed to remote connect to a firewalled Windows computer I set up a reverse VNC connection on that Windows computer that would get initiated whenever I sync'd a file over to the Windows system via Dropbox/Syncthing (those work without port forwarding). Reverse VNC, like Reverse SSH or other connections basically try to initiate the connection out of the firewalled system, it's an interesting workaround when you have no incoming port forwards. Not sure if I'd recommend that type of set up but it is more secure than sending emails so there's that.

If you're able to set up a mesh VPN that might work better but you do have other options if you need them.

[–] hperrin@lemmy.ca 2 points 2 weeks ago

Yes, that is technically possible, but you’ll probably have to design it yourself, because I don’t think anyone else has/will. You need to really consider the security implications of this kind of setup. If anyone discovers how to send an email in the way you’re talking about to your box, they would 100% be able to take over your box.