Tab completion closes SSH connection
I assume the shell is bash
.
Hypothesis
There is set -e
in one of your startup scripts. Then Tab may trigger this: Enabling set -e
in the shell causes bash-completion to terminate the shell.
This is what set -e
does:
Exit immediately if a pipeline […], which may consist of a single simple command […], a list […], or a compound command […] returns a non-zero status. […]
In Bash 4.4.12 in my Debian 9 I can replicate this behavior by invoking set -e
and then using tab completion like in your screenshot.
Testing the hypothesis
Run just false
. If it exits the shell, it means set -e
was active. If so, I expect set +e
to be an ad-hoc fix for your problem. Log in again and check if set +e
makes the problem disappear. It should.
Fixing
You don't want to run set +e
each time you log in. The real fix is to remove set -e
from your startup scripts. Files to check:
~/.bashrc
~/.bash_profile
~/.bash_login
~/.profile
/etc/profile
/etc/bash.bashrc
Some of them may not exist and it's normal. Not every file is used in your particular case, even if they all exist. The list is not exhaustive; these scripts can source other scripts and there is --rcfile
option of Bash to source any file.
My point is: after confirming that set -e
is the culprit, you need to track it down in your shell startup sequence and delete it. Investigating why/how it got there may lead to interesting conclusions, but such research is probably not necessary if you just want to fix the issue in question.
Note bash -e
runs a shell with set -e
active from the start, so exec bash -e
in a startup script would give similar symptoms.