Wednesday, November 13, 2024

ssh – Terminal stuck at every launch until Ctrl+C

Every time I successfully login to a remote server using ssh, the zsh terminal would stuck unless I do a Ctrl+C. There’s no problem with the ssh login. It also requires three Ctrl+C after I type exit for it to really exit the ssh connection every time.

To see if anything’s wrong with ~/.zshenv or ~/.zshrc, I commented out all of their content and added echo "End of ~/.zshenv" at the end of ~/.zshenv, and echo "End of ~/.zshrc" at the end of ~/.zshrc, the output of is as following:

Last login: Thu Aug  1 00:13:12 2024 from XX.XX.XXX.XXX
+/u/username/.zshenv:159> echo 'End of ~/.zshenv'
End of ~/.zshenv
+/etc/zprofile:6> [ -x /usr/libexec/path_helper ']'
+/etc/zprofile:7> /usr/libexec/path_helper -s
+/etc/zprofile:7> eval 'PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin";' export 'PATH;'
+(eval):1> PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin
+(eval):1> export PATH
+/etc/zshrc:7> [[+/etc/zshrc:7> locale LC_CTYPE
+/etc/zshrc:7> [[ US-ASCII == UTF-8 ]]
+/etc/zshrc:12> disable log
+/etc/zshrc:15> HISTFILE=/u/username/.zsh_history
+/etc/zshrc:16> HISTSIZE=2000
+/etc/zshrc:17> SAVEHIST=1000
+/etc/zshrc:20> setopt BEEP
+/etc/zshrc:24> [[ -r /u/username/.zkbd/xterm-256color-apple ]]
+/etc/zshrc:27> typeset -g -A key
+/etc/zshrc:29> [[ -n $'\C-[OP' ]]
+/etc/zshrc:29> key[F1]=$'\C-[OP'
+/etc/zshrc:30> [[ -n $'\C-[OQ' ]]
+/etc/zshrc:30> key[F2]=$'\C-[OQ'
+/etc/zshrc:31> [[ -n $'\C-[OR' ]]
+/etc/zshrc:31> key[F3]=$'\C-[OR'
+/etc/zshrc:32> [[ -n $'\C-[OS' ]]
+/etc/zshrc:32> key[F4]=$'\C-[OS'
+/etc/zshrc:33> [[ -n $'\C-[[15~' ]]
+/etc/zshrc:33> key[F5]=$'\C-[[15~'
+/etc/zshrc:34> [[ -n $'\C-[[17~' ]]
+/etc/zshrc:34> key[F6]=$'\C-[[17~'
+/etc/zshrc:35> [[ -n $'\C-[[18~' ]]
+/etc/zshrc:35> key[F7]=$'\C-[[18~'
+/etc/zshrc:36> [[ -n $'\C-[[19~' ]]
+/etc/zshrc:36> key[F8]=$'\C-[[19~'
+/etc/zshrc:37> [[ -n $'\C-[[20~' ]]
+/etc/zshrc:37> key[F9]=$'\C-[[20~'
+/etc/zshrc:38> [[ -n $'\C-[[21~' ]]
+/etc/zshrc:38> key[F10]=$'\C-[[21~'
+/etc/zshrc:39> [[ -n $'\C-[[23~' ]]
+/etc/zshrc:39> key[F11]=$'\C-[[23~'
+/etc/zshrc:40> [[ -n $'\C-[[24~' ]]
+/etc/zshrc:40> key[F12]=$'\C-[[24~'
+/etc/zshrc:41> [[ -n $'\C-[[1;2P' ]]
+/etc/zshrc:41> key[F13]=$'\C-[[1;2P'
+/etc/zshrc:42> [[ -n $'\C-[[1;2Q' ]]
+/etc/zshrc:42> key[F14]=$'\C-[[1;2Q'
+/etc/zshrc:43> [[ -n $'\C-[[1;2R' ]]
+/etc/zshrc:43> key[F15]=$'\C-[[1;2R'
+/etc/zshrc:44> [[ -n $'\C-[[1;2S' ]]
+/etc/zshrc:44> key[F16]=$'\C-[[1;2S'
+/etc/zshrc:45> [[ -n $'\C-[[15;2~' ]]
+/etc/zshrc:45> key[F17]=$'\C-[[15;2~'
+/etc/zshrc:46> [[ -n $'\C-[[17;2~' ]]
+/etc/zshrc:46> key[F18]=$'\C-[[17;2~'
+/etc/zshrc:47> [[ -n $'\C-[[18;2~' ]]
+/etc/zshrc:47> key[F19]=$'\C-[[18;2~'
+/etc/zshrc:48> [[ -n $'\C-[[19;2~' ]]
+/etc/zshrc:48> key[F20]=$'\C-[[19;2~'
+/etc/zshrc:49> [[ -n $'\C-H' ]]
+/etc/zshrc:49> key[Backspace]=$'\C-H'
+/etc/zshrc:50> [[ -n $'\C-[[2~' ]]
+/etc/zshrc:50> key[Insert]=$'\C-[[2~'
+/etc/zshrc:51> [[ -n $'\C-[[3~' ]]
+/etc/zshrc:51> key[Delete]=$'\C-[[3~'
+/etc/zshrc:52> [[ -n $'\C-[OH' ]]
+/etc/zshrc:52> key[Home]=$'\C-[OH'
+/etc/zshrc:53> [[ -n $'\C-[OF' ]]
+/etc/zshrc:53> key[End]=$'\C-[OF'
+/etc/zshrc:54> [[ -n $'\C-[[5~' ]]
+/etc/zshrc:54> key[PageUp]=$'\C-[[5~'
+/etc/zshrc:55> [[ -n $'\C-[[6~' ]]
+/etc/zshrc:55> key[PageDown]=$'\C-[[6~'
+/etc/zshrc:56> [[ -n $'\C-[OA' ]]
+/etc/zshrc:56> key[Up]=$'\C-[OA'
+/etc/zshrc:57> [[ -n $'\C-[OD' ]]
+/etc/zshrc:57> key[Left]=$'\C-[OD'
+/etc/zshrc:58> [[ -n $'\C-[OB' ]]
+/etc/zshrc:58> key[Down]=$'\C-[OB'
+/etc/zshrc:59> [[ -n $'\C-[OC' ]]
+/etc/zshrc:59> key[Right]=$'\C-[OC'
+/etc/zshrc:63> [[ -n $'\C-[[3~' ]]
+/etc/zshrc:63> bindkey $'\C-[[3~' delete-char
+/etc/zshrc:64> [[ -n $'\C-[OH' ]]
+/etc/zshrc:64> bindkey $'\C-[OH' beginning-of-line
+/etc/zshrc:65> [[ -n $'\C-[OF' ]]
+/etc/zshrc:65> bindkey $'\C-[OF' end-of-line
+/etc/zshrc:66> [[ -n $'\C-[OA' ]]
+/etc/zshrc:66> bindkey $'\C-[OA' up-line-or-search
+/etc/zshrc:67> [[ -n $'\C-[OB' ]]
+/etc/zshrc:67> bindkey $'\C-[OB' down-line-or-search
+/etc/zshrc:70> PS1='%n@%m %1~ %# '
+/etc/zshrc:73> [ -r /etc/zshrc_ ']'
+/u/username/.zshrc:41> echo 'End of ~/.zshrc'
End of ~/.zshrc

And then it’s stuck until a Ctrl+C is sent.
It does seem that ~/.zshenv and ~/.zshrc are finished executing but still somehow get stuck after that. So the solution to this question does not apply.

I also found out that ZDOTDIR and USER_ZDOTDIR are both empty variables after Ctrl+C, even though the ~/.zshenv and ~/.zshrc are executed. Tried in vscode, and the problem persists. But ZDOTDIR, USER_ZDOTDIR, and VSCODE_ZDOTDIR are home directory in vscode. I’m in desperate need of any suggestions that might help solving this issue! Appreciate it!

Related Articles

Latest Articles