0

I'm sshing from my Mac to an Ubuntu machine, but for some reason the key bindings do not work properly. For example when I try to run the tmux shortcut CTRL+b it returns ^B.

The closest questions I could find around is this where different combinations of the stty command has been proposed. I tried them all but none solved the issue. I have checked my .bashrc file but I can't find anything aliasing the CTRL key!

I would appreciate if you could help me know what is the problem and how I can solve it.

P.S.1. I was asked to run the locale and locale -a commands and add the results here:

$ locale
LANG=en_US.UTF-8
LANGUAGE= LC_CTYPE="en_US.utf8" 
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8" 
LC_COLLATE="en_US.utf8" 
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8" 
LC_PAPER="en_US.utf8" 
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8" 
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8" 
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=en_US.utf8

$ locale -a 
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IL
en_IL.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX

P.S.2 I have posted my .bashrc and stty -a here.

wjandrea
  • 14,109
  • 4
  • 48
  • 98
Foad
  • 833
  • 6
  • 9

1 Answers1

0

You need to ensure that both the Ubuntu machine and the Mac have the proper locale settings.

For Ubuntu, you can do this by running these commands:

sudo locale-gen en_US.UTF-8
sudo update-locale

After double-checking Ubuntu, let's focus on the Mac. It is most likely that your Mac is causing the issue, though. This will be dependent on the terminal emulator that you're using. If you go into Terminal app settings, be sure you have Set locale environment variables on startup enabled, and set to Unicode (UTF-8).

Once your locales match, both systems should respond similarly to the same key presses.

You can check your current settings by issuing the locale command on each of the machines.

Alternatively, locale can also be adjusted by setting/changing these environmental variables. For example, these can be exported in .bashrc, or some other file, optionally sourced, though some may argue they belong in .profile:

export LANG="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_NUMERIC="en_US.UTF-8"
export LC_TIME="en_US.UTF-8"
export LC_COLLATE="en_US.UTF-8"
export LC_MONETARY="en_US.UTF-8"
export LC_MESSAGES="en_US.UTF-8"
export LC_PAPER="en_US.UTF-8"
export LC_NAME="en_US.UTF-8"
export LC_ADDRESS="en_US.UTF-8"
export LC_TELEPHONE="en_US.UTF-8"
export LC_MEASUREMENT="en_US.UTF-8"
export LC_IDENTIFICATION="en_US.UTF-8"
export LC_ALL=

While this example is 'typical', it has been suggested to set the LC_ALL variable to en_US.UTF-8, as well, and is reported to work for both Terminal and iTerm2:

export LC_ALL="en_US.UTF-8"
wjandrea
  • 14,109
  • 4
  • 48
  • 98
earthmeLon
  • 11,042
  • 1
  • 36
  • 60
  • Tried the commands, did not help. My mac terminal appears to be ok. when I open it I can run all the key shortcuts with no issues. The settings are exactly as you suggest. – Foad Dec 06 '18 at 22:33
  • I've updated the answer to include [new information](https://apple.stackexchange.com/a/121558/133039), which ultimately comes from [this answer](https://stackoverflow.com/a/8161863/416646). – earthmeLon Dec 06 '18 at 22:36
  • I tried them all, none made any difference except the `export LC_ALL=”en_US.UTF-8″` returns `-bash: warning: setlocale: LC_ALL: cannot change locale (”en_US.UTF-8″)` while `locale -a` shows that `en_US.utf8` is indeed installed! – Foad Dec 06 '18 at 22:44
  • I tried them also on mac terminal, reopened the terminal and sshed back to see the issue is still there. :( – Foad Dec 06 '18 at 22:48
  • Yes, you should be adjusting the Mac `~/.profile` with these exports, restarting your terminal, and trying to access Ubuntu again. Take a moment to read over the [answers for this question](https://stackoverflow.com/questions/7165108/in-os-x-lion-lang-is-not-set-to-utf-8-how-to-fix-it/). – earthmeLon Dec 06 '18 at 22:50
  • did so both for ubuntu and mac, rebooted the server, issues is still there. I should specify again that the mac terminal is fine. I can run all the commands perfectly fine. Maybe it would help that I have installed the `Meslo LG M regular for powerline 11pt.` font? – Foad Dec 06 '18 at 22:58
  • I'm not entirely sure. Can you edit your question to include the output of both `locale` and `locale -a` on both machines? This will probably be good information others to help you. – earthmeLon Dec 07 '18 at 00:06
  • Make sure to use regular quotes and not these fancy ones. Also, the original problem is unlikely to do anything with locales. – egmont Dec 07 '18 at 00:10
  • 1
    @earthmeLon Why do you think that "`”`" will work on the terminal? Use normal "`"`" instead. – N0rbert Dec 07 '18 at 09:19
  • @earthmeLon added the `locale` results. – Foad Dec 08 '18 at 00:37
  • @egmont any idea what it could be then?! – Foad Dec 08 '18 at 00:37
  • 1
    More like stty settings, TERM variable, other env variables. Really not sure. (All the locales in practical use are ASCII-compatible, and there aren't any extended characters in sight, that's why it's sure irrelevant.) – egmont Dec 08 '18 at 09:21