If you want to run an interactive service that you can "connect" to, install the
screen package, so you can use
screen to create a new session and run your script in detached mode, with something like
setpriv --reuid user --init-groups --reset-env screen -d -m -S sessionname python3 /path/to/script.pyin your init script. This command starts the script as a separate process as user
user, and returns immediately.
Afterwards, user
user can run
screen -r sessionnameto reconnect to the script, from any terminal; even from an SSH connection. To detach from the script, press Ctrl+A then Ctrl+D.
screen and other similar utilities work by creating
pseudoterminals when needed. These are character device pairs, a slave (which acts basically indistinguishably from a TTY device), and a master (that controls the input and output to the slave). In your particular case, Linux
pts support, also known as UNIX 98 pseudoterminal support, will be used and the character devices reside under
/dev/pts/.
You can also run a script or program using a specific
console terminal using
openvt as root:
openvt -c 8 -- python3 /path/to/script.pyor
openvt -c 8 -- setpriv --reuid user --init-groups --reset-env python3 /path/to/script.pyThis starts the Python script connected to
/dev/tty8 as root (first) or user
user (second), but without changing the ownership of the tty device. It will fail if the tty is already in use. These too will start the script in a separate process, and return immediately, without waiting for the script to complete.
You can switch the active terminal using e.g. Ctrl+Alt+F8, or running
chvt 8, but only from the console terminal, and not when connecting using e.g. SSH.
This kind of stuff is normally done only when you replace the entire
init system, though; with say passwordless login shells in a couple of TTYs, but one or more primary ones providing some kind of a text-based full-screen interface (TUI), so that the user can switch between them using Ctrl+Alt+F
n or Ctrl+Alt+◀ and Ctrl+Alt+▶, but only from the local console terminal, not over SSH etc.