Skip to content

Instantly share code, notes, and snippets.

@bmidgley
Created January 1, 2024 19:08
Show Gist options
  • Save bmidgley/8324439aa006287771cdc5cd2be5e22d to your computer and use it in GitHub Desktop.
Save bmidgley/8324439aa006287771cdc5cd2be5e22d to your computer and use it in GitHub Desktop.
virtual serial port
root@serial:~# cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
(
while sleep 60
do socat /dev/ttyAMA0,b19200,raw,echo=0 TCP:localhost:2000
done
) &
exit 0
root@mars:~# cat /etc/ser2net.yaml
%YAML 1.1
---
# This is a ser2net configuration file, tailored to be rather
# simple.
#
# Find detailed documentation in ser2net.yaml(5)
# A fully featured configuration file is in
# /usr/share/doc/ser2net/examples/ser2net.yaml.gz
#
# If you find your configuration more useful than this very simple
# one, please submit it as a bugreport
connection: &con0096
accepter: tcp,2000
timeout: 0
enable: on
options:
kickolduser: true
telnet-brk-on-sync: true
connector: serialdev,/dev/ttyUSB0,nobreak,19200n81,local
root@mars:~# cat /etc/systemd/system/ssh-tunnel-persistent.service
[Unit]
Description=Persistent SSH Tunnel
After=network.target
[Service]
Restart=on-failure
RestartSec=5
ExecStart=/usr/bin/ssh -NTC -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -R 2000:localhost:2000 tunnel@serial
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment