Is it possible to change what tty a terminal emulator is connected to?

If I have a terminal emulator (say, xterm) by default it connects to a pseudoterminal like /dev/pts/3

What I would like to know is if it is possible to connect it directly to, say, tty1?

Could I connect to a tty and have it display the login prompt as if I was really at that tty (by pressing Ctrl+Alt+F1 for example)?

Asked By: Cameron Ball

||

Yes and no. You can redirect its child’s in/out streams – probably your shell – but xterm will have little involvement there. xterm owns the master side of that pty – it does an open on /dev/ptmx and in the process creates /dev/pts/3. But it gives it away – your shell owns that pty now, as xterm makes it the session leader. All xterm does is take the input from the keyboard and pass it to the shell and take output from the shell and pass it to the screen. In this way xterm performs multiplexing functions – subdividing and redirecting input and output between pseudoterminals, but not much else is relevant here once the pty is up.

The virtual consoles, though, are another matter. If your user account is assigned the proper filesystem permissions, you can read them and write to them from other processes – or other terminals – in simpler ways – as in, you needn’t pass input/output through a master-side to talk a process running on the slave-side. You can easily do these things in almost every way that matters except where login is concerned. It will kill any listener on that device and will only accept keyboard input. That is its job.

Still, I suspect you’re looking for some authentication solution. You can get virtually the same level of security with:

ssh -t localhost 'exec some process'

That will securely prompt you for authentication then log you into the machine and exec some process in a new pseudoterminal – you can do that from xterm, say.

Answered By: mikeserv
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.