Why is my Terminal typing weird characters?
When I'm connected to SSH using my Mac's Terminal and use my arrow keys, it prints characters like ^[[C
instead of moving the cursor. Why is that and how do I fix it?
3 Replies
That certainly is a strange behavior. The images supplied on our platform use pretty much stock versions of the distributions they provide, aside from a few minor tweaks to make them work better with our platform. There isn't anything in our images that should cause that to happen, but I may have an idea.
Many terminal applications for Mac will replace arrow keys with characters like ^[[A
, ^[[C
, etc if the Option key (or another modifier key) is being held down. I've had this happen to me a few times. In my own experience this happens when something is pressing down on the key, or if a bluetooth keyboard is connected that could have something sitting on it. In the past, I've found my keyboard in my laptop bag, having been accidentally left on. Alternatively, if there is an issue with the keyboard itself, it could be responsible for what you're seeing. If you have another keyboard I recommend trying that to rule it out. If you're still having trouble, using a different Terminal emulator may help.
It's what's sent from the keyboard. If a script or something is running in the foreground this can happen too when trying to use arrow keys. It's a pretty normal occurrence not speicifc to Linode.
You could try:
Terminal -> Preferences -> Shells open with -> [select] Command (complete path)
then paste
/bin/bash
That potential solution is taken from an answer on stackoverflow that also has more details about this:
This is a "bash" problem: that you can't use your keys like Ctrl-L to clear the screen, up-arrow for history, etc.
Searched high and low for the solution, and finally, after much debugging, Perplexity.ai showed me the solution:
This is because you are not using bash as the default shell. Simply type "bash" in your terminal to switch to the Bash shell, and see that the keys now magically work!
Change your default shell to Bash:
If you want to make Bash your default shell, you can use the chsh command. First, if you typed "bash" earlier, "exit" so you are in the top-level shell. Then "chsh -s /bin/bash". Then exit your ssh session, and log back in.