Easy way is probably two usb-serial dongles and a null modem, if you don't need huge amounts of throughput.
https://www.digikey.ca/en/products/detail/ftdi-future-techno...
The only security barrier that macOS implements against this kind of attack is, that you must manually confirm after you connected that "keyboard", for system to enable it.