iTerm session hangs when connecting to AWS instance

I'm having a problem with connecting to Ubuntu 16.04 running on EC2 using public key and the iTerm terminal. The ssh session is being opened, the user is being logged in, bash prompt is shown, but after executing any command e.g. &quotls&quot iTerm session hangs and closes after some time.

I do not experience such behavior when logging into that instance using a standalone iTerm connection.