The world wants you to clean your screen.
As I said at https://unix.stackexchange.com/a/233855/5132 and indeed in the indirectly referenced mailing list discussion ☺ …
Wanting not to clear a virtual terminal between log-off and subsequent log-on is very much swimming against the tide, as Greg Wooledge and others have discovered. The presence of sensitive output from privileged users, or bosses, remaining after log-off has been a security problem for Unices (and indeed other timesharing remote-access operating systems) since the 1970s, and it takes a lot of effort to undo all of the things that people have put in to avert this problem. As you have observed, they have put in several overlapping mechanisms that do this.
- Many systems have a
clear_console
command in their shell logout scripts as standard. (This is problematic in its own right, as it doesn't play well with graphical programs running on kernel virtual terminal #1, and doesn't work with any other kinds of terminals, virtual or real.)This command has to be removed.
- The default in getty programs aimed at virtual terminals, such as
mingetty
, is to clear the terminal. (It does this before log-on, meaning that terminal output can remain unerased if a TTY login service is stopped. Ironically, this functionality would have been better placed in login
, which thanks to the necessities of PAM is still running at log-off.)The --noclear
option has to be deployed to disable this. On systemd operating systems this involves writing one or more unit file override files, changing the ExecStart
setting, or simply pointing autovt@.service
at a local unit file of one's own devising.
- systemd's supplied
getty@.service
template service unit sets TTYVTDisallocate=yes
which instructs systemd to clear a kernel virtual terminal. (This again doesn't work with any other kinds of terminals, not even user-space virtual terminals, as partly reflected in its name.)This too has to be removed, again with an override or a different service template pointed to by autovt@.service
.
They are not entirely overlapping, of course. mingetty
isn't useful for real terminals connected via serial devices; clear_console
is, oddly, part of the Bourne Again shell package and isn't invoked by people who have the Korn, Z, Almquist, Fish, Watanabe, or other shell as their user account's interactive login shell; and the systemd TTYVTDisallocate
mechanism has no applicability to non-systemd operating systems.
As I said in the mailing list discussion several years ago, console_clear
is doubly unnecessary. Since 2011 the Linux built-in terminal emulator has supported the ED 3
control sequence for clearing the scrollback buffer, so the mucking around with switching virtual terminals that has these detrimental side-effects isn't necessary in the first place. I added a console-clear
command to the nosh toolset several years ago, that emits this control sequence (and is thus usable with more than just the Linux built-in terminal emulator, as well as working over a remote connection). The ncurses clear
command also nowadays knows to emit the relevant control sequences, if terminfo says so.
And of course console-terminal-emulator
clears its display buffer at terminal hangup as standard.
Further reading