^[[A or nothing at all. This happens because PuTTY sends escape sequences that the remote shell does not interpret correctly as history navigation commands. The root cause usually lies in the interaction between the TERM environment variable, the stty settings, and the specific readline configuration used by Bash or Zsh on the Ubuntu server.
To resolve this, you must ensure that the terminal type advertised by PuTTY matches what the Ubuntu shell expects, and that the shell’s line editing capabilities are correctly initialized. This involves checking several layers of configuration, from the PuTTY connection settings to the .bashrc file on the remote machine.
Verify Terminal Type Settings in PuTTY
The first step is to confirm that PuTTY is advertising the correct terminal type to the SSH server. If the terminal type is incorrect, the remote application will send escape sequences that your local terminal cannot parse, leading to broken input handling. Navigate to the PuTTY configuration window before establishing your connection. Go to the Connection category, then expand it to find the Data sub-menu. Look for the field labeledTerminal-type string. By default, this should be set to xterm. However, Ubuntu 22.04 often relies on features specific to modern terminals. Try changing this value to xterm-256color if it is not already set. This setting ensures that the terminal supports extended color codes and more robust control sequences, which can sometimes improve input stability. After making this change, save the session profile and reconnect to test if the up-arrow key now retrieves history entries.
Check Remote Shell Configuration
If the PuTTY settings are correct but the issue persists, the problem likely lies within the shell configuration on the Ubuntu side. The Bash shell uses the Readline library to handle command-line editing, including history navigation. If Readline is misconfigured or disabled, arrow keys will not function as expected. Connect to your Ubuntu server and open the.bashrc file in your preferred text editor, such as nano ~/.bashrc or vim ~/.bashrc. Scroll to the bottom of the file and look for any lines that modify bind settings or disable Readline. Specifically, check for any commented-out sections related to set -o vi or custom key bindings that might interfere with the default Emacs-style editing mode. Ensure that the file ends with standard initialization commands. If you recently modified this file, try temporarily renaming it to .bashrc.bak and restarting the shell to see if the default behavior returns. This helps isolate whether a custom configuration is causing the conflict.
Inspect stty Settings
Another common culprit is the terminal line discipline settings managed bystty. These settings control how the terminal driver processes input characters, including backspace, tab, and special keys. If these settings are corrupted or reset incorrectly during the SSH session, input handling can break.
Run the command stty -a in your remote shell to display the current terminal settings. Look for the section labeled intr = ^C; quit = ... and other similar flags. Pay attention to the erase, kill, and eof settings. They should typically be set to standard values like ^? (backspace) or ^U (Ctrl+U). If you see unusual characters or if the output seems truncated, it may indicate that the terminal state is inconsistent. You can try resetting these settings by running stty sane. This command attempts to restore reasonable defaults for terminal settings based on the current terminal type. After running this, test the arrow keys again to see if history access is restored.
Alternative: Use ssh.exe instead of PuTTY
If you continue to experience issues with PuTTY despite adjusting the configurations above, consider using the native OpenSSH client included with Windows 10. As discussed in our guide on PuTTY vs ssh.exe on Windows for ssh connections, the native client offers different integration with the Windows console subsystem, which can sometimes resolve terminal emulation quirks. Open PowerShell or Command Prompt on your Windows host and use thessh command to connect to your Ubuntu server. For example, run ssh user@ubuntu-ip-address. The native SSH client uses the Windows Console API directly, which handles terminal types and input streams differently than PuTTY’s emulated terminal. In many cases, this eliminates the need for manual terminal type adjustments because the client negotiates capabilities automatically. Test the arrow keys in this environment to determine if the issue is specific to PuTTY’s emulation layer.
Debugging with strace
For advanced users who need to pinpoint exactly where the input is failing, you can use debugging tools to trace system calls. Runningstrace -f -e read,write bash allows you to see what data the shell is reading from the terminal and what it is writing back. This can reveal if escape sequences are being received but ignored, or if they are not being sent at all. While this requires some technical expertise, it provides definitive evidence of whether the problem is on the network, the terminal emulator, or the shell itself.
Frequently Asked Questions
Why do I see ^[[A instead of my previous command?
This indicates that the terminal is displaying raw escape sequences rather than interpreting them as navigation commands. It usually means the TERM variable is set incorrectly or Readline is not active. Fixing the terminal type string in PuTTY to xterm-256color typically resolves this.
Does disabling Vi mode affect history access?
Yes, if you switch to Vi mode using set -o vi, the default arrow key bindings may change or require different key combinations. Ensure you are in Emacs mode (set -o emacs) for standard arrow key history navigation unless you have explicitly configured Vi bindings.
Can firewall settings block terminal input signals?
No, firewall settings generally do not block terminal input signals like arrow keys, as these are part of the established SSH data stream. Input issues are almost always related to software configuration within the terminal emulator or the shell, not network security policies.
Is reinstalling PuTTY necessary to fix this issue?
Reinstalling PuTTY is rarely necessary. Most history access issues are resolved by correcting configuration settings such as the terminal type string or remote shell configurations. Only consider reinstalling if the installation files themselves are corrupted, which is uncommon.
How does Cygwin compare to PuTTY for this issue?
Cygwin provides a Unix-like environment natively on Windows, which can sometimes offer smoother terminal integration compared to PuTTY’s emulation. However, both rely on correct terminal type negotiation. For more details on running Cygwin terminals, see our article on Running Cygwin Terminal with Current Cygwin Installation on Windows 10.