There is another way to go about this bit is slightly more complex, and would require an additional "server" somewhere. This server could be another embedded Linux system if you so wished. Such as a beaglebone.
But basically how this works if you have an MQTT broker running locally, with the MQTT subscriber( the remote beaglebone ) out in the wild somewhere. The MQTT protocol while technically not very secure. Can be made very secure if some serious thought is put into how you architect your complete system. MQTT works by using a publish, and subscribe model. So one can pretty much bullet proof how a publisher, and subscriber interact with one another.
E.G. The Broker acts as a Publisher and Subscriber as well as does the remote system. So the local, and remote system each have their respective Published, and subscribed values. Which makes it very hard for "The man in the middle" attacks, and probably impossible for input injection.
So this is actually a part of a set of articles by the same person I believe. But this first article gives a pretty good overview of MQTT, and the utilities available to Linux( debian ). Technically, you could even write a set of shell scripts to accomplish what you want. But personally I'd probably rather at least wrap these utilities from within another high level language. Maybe even just use their API, and write my own code in C . . . YMMV.
After saying all of the above however. You'd probably want to completely lock your remote and lcoal system down completely, and avoid using wireless or bluetooth on either end. To be the most secure.