Tuesday, 20 August 2019

linux - Tab completion closes SSH connection


I am using SSH connection to log into my Raspberry Pi. I used tab completion over SSH before and that worked perfectly. But now I am getting the "connection closed" message whenever I try to use tab completion over SSH.


screenshot



Answer



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.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...