Configure a serial port (e.g., /dev/ttyS0) to allow both incoming getty login and outbound terminal connections without conflicts.
apt install util-linux procpsCreate /etc/systemd/system/[email protected]/bidirectional.conf:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noclear --keep-baud --wait-cr --nohangup --noissue 115200,38400,9600 %I xterm-256colorEnable:
systemctl daemon-reload
systemctl enable [email protected]
systemctl start [email protected]Add to /etc/inittab:
T0:23:respawn:/sbin/agetty -L --wait-cr --nohangup --noissue ttyS0 115200 xterm-256color
Reload:
init qapt install mgetty mgetty-faxEdit /etc/mgetty+sendfax/mgetty.config:
port ttyS0
speed 115200
direct y
fax n
data y
blocking n
port-owner uucp
port-group dialout
port-mode 0660
term xterm-256color
Add to /etc/inittab:
T0:23:respawn:/usr/sbin/mgetty ttyS0
Reload:
init qCreate /usr/local/bin/bidir-getty:
#!/bin/bash
TTY=$1
stty -F /dev/$TTY -echo -icanon min 0 time 0
while :;do
if fuser /dev/$TTY &>/dev/null;then sleep 1;continue;fi
read -rsn1 -t86400 c </dev/$TTY || continue
TERM=xterm-256color flock -x -n /var/lock/LCK..$TTY /sbin/agetty --login-options "$c" $TTY 115200 xterm-256color
doneMake executable:
chmod +x /usr/local/bin/bidir-gettyCreate /etc/systemd/system/[email protected]:
[Unit]
Description=Bidirectional Getty on %I
After=systemd-user-sessions.service
[Service]
ExecStart=/usr/local/bin/bidir-getty %I
Restart=always
StandardInput=tty
StandardOutput=tty
[Install]
WantedBy=multi-user.targetEnable:
systemctl daemon-reload
systemctl enable [email protected]
systemctl start [email protected]Add to /etc/inittab:
T0:23:respawn:/usr/local/bin/bidir-getty ttyS0
Reload:
init qscreen /dev/ttyS0 115200
# or
minicom -D /dev/ttyS0Connect from another device and press Enter to trigger login prompt.
- --wait-cr: Getty waits silently for CR/LF before displaying login prompt
- --nohangup: Doesn't send hangup signal, allows port sharing
- --noissue: Suppresses pre-login banner
- flock: File locking prevents simultaneous access conflicts
- fuser: Checks if port is in use by another process
When outbound program (screen/minicom) opens the port, getty detects it's locked and waits. When released, getty resumes listening for incoming connections.