Ssh – preventing the screen from being cleared when exiting an ssh session

sshzsh

I have rdist set up to push out some of my dot files to all the remote machines that I need to ssh into. I also have zsh as my default shell on all of those machines.

When I ssh into a machine and then exit, the screen is cleared. I find this behavior bothersome. My attempt to prevent this behavior was to comment out the /usr/bin/clear line in my .logout file. I then dist'd this updated file out to all the remote machines.

The trouble is, that didn't work. I am unsure about this, but I thought .logout was for csh, but I don't have a .zlogout (or .bash_logout either, for that matter). There's nothing in any of my other dot files (e.g., .zshrc, .zshenv) that seems like it would cause the screen to clear. When I ssh into a remote machine, then exec zsh (in order to get a "fresh" shell session), then the terminal will not clear upon exiting the ssh session. But otherwise, the problem persists – on any machine that I connect to, the screen clears upon exiting.

For what it's worth, I don't appear to have the same problem when I set my default shell on the remote machines to bash. So I assume the problem is with zsh.

I checked the dot files to make sure they got dist'd correctly (they did). Aside from this, I'm running out of ideas… why does my terminal keep getting cleared when exiting ssh?

edit: I found the source of the problem: There is a /etc/zlogout file on many of the remote machines. I don't have sudo privileges on many of these machines and I don't want to globally affect users; is there a way to override the functionality in /etc/zlogout? Simply making a $HOME/.zlogout file doesn't seem to work.

Best Answer

Zsh on RHEL 7 behaves the same a way, i.e. during ssh logout the terminal is cleared.

(Depending on the terminal the last terminal output is lost, or it is just scrolled out of view.)

This is because of /etc/zlogout - which is part of the zsh package - is containing:

clear

(it does not contain other commands)

You can override this clearing in your own .zlogout file via completely disabling the reading of /etc/zlogout during logout:

$ cat ~/.zlogout
setopt norcs

Disabling the rcs option disables the sourcing of certain run control files - probably hence the name: no Run Control Sourcing

Related Question