No announcement yet.

Clear the Bash Screen when Logging Out

  • Time
  • Show
Clear All
new posts

  • Clear the Bash Screen when Logging Out

    Private information can be a lot of things. Sometimes information is exposed by the shouldersurfing person next to you or the dumbsterdiving cleaning lady. Sometimes it is just some left over text on a logged-out console screen.
    Here I will show you how to have the screen cleared by automation when logging out of your console.
    Basically there are two ways of doing it but some paranoid administrators might do both.

    The first way is to just put a "clear" in the ".bash_logout" script placed in your home folder.
    Add the following entry.

    [ "$PS1" ] && clear

    Another way of doing it is to create a trap that is executed on shell termination.
    This should be placed in the ".bash_profile" file also located in your home directory.

    trap ' [ "$PS1" ] && clear ' 0

    If you want it to work for new users also it would be best to put those in the files placed in the "/etc/skel" directory also.
    This is where new users get their ".profile" and ".basl_logout" files from when they are first created.

    Remark that this will not work if you use a remote ssh client like Putty or TeraTerm. The screen will be cleared but the clients has a local buffer and it will most likely be possible to just scroll up the screen using the scroll bar.
    Also this do not affect the command history.
    You should always clear the client buffer or exit it all together when you leave your computer unattended.
    Certified Security Geek