Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I like to switch to tty1 whenever I have a root task to accomplish. The unfortunate thing about this is that if someone were to switch to tty1 without me noticing, they might be able to read the events that occurred before the logout of root. I don't want this occurring. So, how do I remove such information before a complete exit?
For example, imagine I use
Code:
apt-get -d upgrade
.
It leaves a trail of information whenever I type in
Code:
exit
.
If I remain in tty1, all I have to do is shift+"page up" in order to view what happened before the exit. If I switch to a different tty and then back to tty1, I can't shift+"page up."
I want that same effect but while staying in tty1.
How do I accomplish such a thing?
I like to switch to tty1 whenever I have a root task to accomplish. The unfortunate thing about this is that if someone were to switch to tty1 without me noticing, they might be able to read the events that occurred before the logout of root. I don't want this occurring. So, how do I remove such information before a complete exit?
The "SHIFT+up" thing, as far as I know, is a terminal configuration thing. The lines shown are shell history. Clearing those lines means clearing your shell history and setting root envvars that govern shell history logging. Since you're performing root account tasks I'd strongly suggest keeping a record of things. If not in the root shell history file then elsewhere.
The "SHIFT+up" thing, as far as I know, is a terminal configuration thing. The lines shown are shell history. Clearing those lines means clearing your shell history and setting root envvars that govern shell history logging...
Since shell history buffer gets written on exit you could 'echo "mv -f /root/.bash_history /root/.bash_history.0"|at now + 1 minutes; logout' inside your shell session and beforehand add HISTFILE=/dev/null and HISTSIZE=0 to the .bashrc. Ksh it'll be .sh_history and .kshrc.
I don't think what you have recommended is what I am looking for.
Well, that's one way to put it. I don't know what shell you run, if it's got multiple sessions open, if you actually run the 'at' service or if you just fat-fingered a command. So I don't even have a clue what you have performed is what you should have.
Distribution: Slackware from 94-09, Debian Since March 09
Posts: 28
Rep:
Quote:
Originally Posted by Cyberman
I like to switch to tty1 whenever I have a root task to accomplish. The unfortunate thing about this is that if someone were to switch to tty1 without me noticing, they might be able to read the events that occurred before the logout of root. I don't want this occurring. So, how do I remove such information before a complete exit?
For example, imagine I use
Code:
apt-get -d upgrade
.
It leaves a trail of information whenever I type in
Code:
exit
.
If I remain in tty1, all I have to do is shift+"page up" in order to view what happened before the exit. If I switch to a different tty and then back to tty1, I can't shift+"page up."
I want that same effect but while staying in tty1.
How do I accomplish such a thing?
I recommend adding the "clear console" command to your logout script. For example, here is my ~/.bash_logout script:
Code:
# ~/.bash_logout: executed by bash(1) when login shell exits.
# when leaving the console clear the screen to increase privacy
if [ "$SHLVL" = 1 ]; then
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
If your system does not have the "clear_console" command available, then create this logout script, and use it when you are on TTY1:
Code:
#!/bin/bash
clear
chvt 2 && chvt 1
logout
Hope this helps...
Last edited by Linuxchuck; 03-15-2009 at 11:02 AM.
Reason: tweaked the script a bit.
Distribution: Slackware from 94-09, Debian Since March 09
Posts: 28
Rep:
Quote:
Originally Posted by unSpawn
Does clear_console only clear the screen or shell history as well? I doubt it.
If I read this thread correctly, Cyberman never asked for a way to clear the shell history. Only the scrollback buffer on consoles. He never mentioned that anyone other than himself logs in as root. Only that he was looking for an automated process to make sure that nobody can walk up to the screen after he has logged out of root from one of the virtual consoles (TTY1-10) and use the scrollback buffer (shift+pgup) to read the commands and output that he had performed prior to logging out.
It's common practice to alias or script logout so that it "clear"s or "reset"s the screen as the last thing it does, especially if working as root. Both clear and reset are standard commands in /usr/bin in all distros.
They are also incredibly useful remotely - often an SSH session will break it's line-lengths and make a mess of the screen and clear with fix it. And equally often, you paste binary data, or run a command that puts binary data onto stdout by accident and it will mess up the whole charset encoding - everything will still "work", but you'll see garbage in place of the characters you type. "Reset" is designed to fix that (and be easy to type even when you can't see what's on screen!).
And equally often, you paste binary data, or run a command that puts binary data onto stdout by accident and it will mess up the whole charset encoding - everything will still "work", but you'll see garbage in place of the characters you type. "Reset" is designed to fix that (and be easy to type even when you can't see what's on screen!).
I'd gotten it into my head that there was a console escape sequence to clear out the scrollback history on the linux Virtual Terminal, but I've been searching all over and I'm buggered if I can find it. It's possible I might have be thinking of FreeBSD though.
Anyway, the following approach will sort of work in a round about way.
Add an INIT string to your getty command line in /etc/inittab.
In my case on slackware which uses agetty it's the -I option.
Code:
c6:12345:respawn:/sbin/agetty -I "\033c\033[12;7]" 38400 tty6 linux
Now, when you logout of your console session, in this example on tty6, inittab with respawn the getty process which will then use the init string to \033c (reset) and \033[12:7] (switch to virtual console 7. In my case X Windows). Because of the VT switch the scroll-back buffer belonging to the previous VT is no longer available if someone were to switch back with ctrl-alt-f6. As long as you don't mind this VT switching it'll ensure the privacy of whatever it was you were doing on the VT prior to logout.
If anyone knows of a control sequence to erase the scrollback itself, I'd be very interested to see it. man "console_codes" doesn't list one.
By the way, there's many other ways to do this. For example, editing /etc/issue:
Code:
^[[H^[[2J
Welcome to my linux box
This issues escape sequences, which clears the virtual console (some distros already have this setup, such as ArchLinux). You could also edit ~/.bash_logout or ~/.logout:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.