A scriptlet for easy writing commands to a virtual terminal. https://spacecruft.org/deepcrayon/wrtty
Go to file
Jeff Moe 77ab00418c PI 2024-06-12 05:53:18 -06:00
wrtty Rename to wrtty 2024-06-11 18:44:07 -06:00
.gitignore fatter ignore 2024-06-11 17:10:22 -06:00
CHANGELOG.txt v0.6.2 2024-06-12 05:39:30 -06:00
LICENSE MIT 2024 2024-06-12 05:52:28 -06:00
README.md PI 2024-06-12 05:53:18 -06:00
poetry.lock Set up project with poetry. Use sudo 2024-06-11 17:40:10 -06:00
pyproject.toml v0.6.2 2024-06-12 05:39:30 -06:00



wrtty is a Python script to write commands to a virtual terminal.

Note: wrtty elevates permissions with sudo because it needs root permissions.

By "virtual terminal", it is meant what is often called the "console", which is slightly different. In this case it is the "virtual terminal" controlled by commands such as chvt (e.g. sudo chvt 3).

Writing to the console can make text appear, but it won't make it execute as a command in a shell. Writing to the virtual terminal, such as /dev/tty1, commands can be run, login on console, etc.

This may be used in a situation where you have ssh access to a machine, but no X/Wayland/VNC running, but you need to run as if you are in front of the machine. This in effect simulates an operator standing in front of a machine, typing on the local keyboard.


Quick install from PyPI. Python setups vary correctly, similar to this should work, such as with Debian:

sudo apt install python3-venv python3-pip
python -m venv venv
source venv/bin/activate
pip install -U setuptools pip wheel
pip install wrtty

PyPI project info:


Help output:

$ wrtty --help
usage: wrtty [-h] [-s STRING] [-t TTY]

write string to tty virtual terminal

  -h, --help            show this help message and exit
  -s STRING, --string STRING
                        string to write (default echo)
  -t TTY, --tty TTY     TTY to use (default /dev/tty1)


Use examples:

wrtty -s "date -uR"
wrtty -t /dev/tty2 --string "clear"


Developers build thusly.

Under Debian stable (Bookworm/12).

Python setup, suit to taste:

git clone https://spacecruft.org/deepcrayon/wrtty
cd wrtty/
pyenv local 3.11 # if pyenv
python -m venv venv
source venv/bin/activate
pip install -U setuptools pip wheel poetry
poetry install


Git source code repository:




I don't know of another application that specifically does this. There are a few old snippets in perl, C, and Python in StackExchange and blogs, but just small examples.

Some linkies:

fcntl — The fcntl and ioctl system calls

Faking input with IOCTL/TIOCSTI

RichardBronosky writevt.c

Construct a command by putting a string into a tty

Unable to fake terminal input with termios.TIOCSTI

send command to another terminal

Can I send some text to the STDIN of an active process running in a screen session?

Linux Kernel Note

I see this configuration option and note in a 6.5 kernel:

Historically the kernel has allowed TIOCSTI, which will push
characters into a controlling TTY. This continues to be used
as a malicious privilege escalation mechanism, and provides no
meaningful real-world utility any more. Its use is considered
a dangerous legacy operation, and can be disabled on most

Say Y here only if you have confirmed that your system's
userspace depends on this functionality to continue operating

Processes which run with CAP_SYS_ADMIN, such as BRLTTY, can
use TIOCSTI even when this is set to N.

This functionality can be changed at runtime with the
dev.tty.legacy_tiocsti sysctl. This configuration option sets
the default value of the sysctl.

Type  : bool
Defined at drivers/tty/Kconfig:152
Prompt: Allow legacy TIOCSTI usage
Depends on: TTY [=y]
    -> Device Drivers
      -> Character devices
        -> Enable TTY (TTY [=y])
          -> Allow legacy TIOCSTI usage (LEGACY_TIOCSTI [=y])




Copyright © 2023, 2024, Jeff Moe.