I am currently working on some Debian@Debian installations with OpenVZ. In general, it works nice and the OpenVZ Wiki is the most useful information source for all questions regarding installation and configuration. I decided not to use the prepared debian kernels with OpenVZ available, since they configured an i386 build. We simply want to use all the nice new commands introduced since the invention of the Pentium
…
We experienced strange problems when resizing a terminal (PuTTY in our case) with a shell at one of the guest Debian systems. In the host Debian system, it works without any problem. We first blamed the program for not handling SIGWINCH the right way. This was not the case, even VIM made it wrong
I started to play with the TERM environment variable setting, but it didn’t got better. I learned several things (from Martin, as usual): The TERM environment variable really is intended to match to the connected terminal client. “linux” terminals are a physically connected monitor and keyboard – keys like Strg+F10 are available. “vt100″ terminals are pretty old hardware, and usually not connected to a Linux box. And both of them are usually not resizable
…
Therefore, a really useful default with SSH is the xterm terminal type. When I use PuTTY, this is the exactly the value of TERM after the SSH login. I learned that changing TERM in your .bashrc file is stupid in this case, since the SSH client itself already requests the right terminal type. The protocol sends (SSH_MSG_CHANNEL_REQUEST, "pty-req") for requesting the pseudo terminal, with parameters for terminal type and initial size. Therefore, the client and the server automatically agree on the same terminal type, and this cannot be the problem. Also the resize activity is covered by a SSH protocol message (SSH_MSG_CHANNEL_REQUEST, "window-change"). This leads to ioctl(TIOCSWINSZ) by SSHD for the pseudo terminal process, and this leads to SIGWINCH for everybody in the process group. In short, if the application is resizable in general, and your SSH tool demands the right terminal type, it should work.
After some reading and Google, I found the right answer. Until now, we entered the guest systems by connecting with SSH to the host system, and entering the guest systems with vzctl enter XXX. And page 100 from the OpenVZ user manual says:
vzctl enter is similar to vzctl exec /bin/bash. The difference between the two is that vzctl enter makes the shell interpreter believe that it is connected to a terminal. As such, you receive a shell prompt and are able to execute multiple commands as if you were logged in to the Virtual Private Server.
Some of the environment variables from the host system (like SSH_TTY) are not inherited to the guest system. We looked at the source code of vzctl, and found src/enter.c which contains the activities on vzctl enter. The function forks, creates a new pseudo terminal (pty_alloc), moves this new process to the intended VZ with an ioctl() to the vzctl file descriptor (/dev/vzctl), starts a new shell in the pseudo terminal, and waits for the ending while connecting host-system-stdin with guest-system-stdout and vice versa. Only some environment variables (like PATH) are configured manually, nothing is inherited. There is also no signal handler for SIGWINCH, which leads to the fact that the vzctl process receives the signal from SSHD, but does not forward it to the shell in the guest system.
We could now patch vzctl, or live with it. The manual anyway says:
However, be aware that vzctl enter is a potentially dangerous command if you have untrusted users inside the Virtual Private Server. Your shell will have its file descriptors accessible for the VPS root in the /proc filesystem and a malicious user could run ioctl calls on it. Never use vzctl enter for Virtual Private Servers you do not trust. That is why, vzctl enter is only supposed to be an off-duty way of connecting to VPSs, not a complete replacement of ssh.
Im sum, vzctl enter is an emergency solution. Install SSH in your guest systems.