aws / amazon-ssm-agent

An agent to enable remote management of your EC2 instances, on-premises servers, or virtual machines (VMs).
https://aws.amazon.com/systems-manager/
Apache License 2.0
1.04k stars 323 forks source link

SSM and xterm issues with zsh #344

Open altjx opened 3 years ago

altjx commented 3 years ago

I have spent quite some time today trying to figure out why my tmux sessions look perfectly fine via SSH compared to when I'm connected to a server via SSM.

For example:

image

This happens with any command that has a pretty extensive output.

As you can see, the tmux panes bleed over. I figured out that it was due to the TERM environment variable. From the SSH session, it was set to xterm-256color and it worked just fine. From the prompt (after connecting via SSM), it was also the same but the tmux session was different.

When I changed this value to ansi it fixed my problem.

However, I'm now having the same issue in docker and I can't set the TERM to ansi because of some other issues. Not sure if there's anything I can "configure" per se, but just wanted to check to see if there's another way I could resolve this issue.

fmiao1618 commented 3 years ago

Hello! Thank you for your post. You are correct in that the normal way of altering the output of the terminal is through modifying the TERM variable. We are actively investigating other methods for altering the output outside of changing the term variable. We were able to reproduce your issue with some commands, such as the 'help' command, but saw that other commands had the correct text wrapping to display all the output correctly. For your issue, is this output truncation issue something that occurs for all long output or specific commands?

One way of preserving your output is to send output to an s3 bucket via the Session Manager preferences. With ECS, you can configure the ecs task role to allow output to be sent to an s3 bucket. You can see the directions for that here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html With normal ec2 instances, you can also configure the instance role to have s3 permissions. You can see the directions for that here: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-logging.html

altjx commented 3 years ago

Thanks for your comment @fmiao1618.

For those who may be looking to do this in a more automated, convenient way, just add this to the SSM preferences so that this run on every SSM agent connect:

export LANG=en_US.UTF-8; export TERM=ansi
fmiao1618 commented 3 years ago

Hello! Session Manager by default sets xterm-256color as the TERM variable for shell sessions. To change this value, you can either directly alter it in the shell session or set it in the shell profile to change it automatically when you start a session.

justinmk3 commented 2 years ago

Related:

kdesjard commented 1 year ago

Problem with TERM=ansi is that mouse mode does not work.