Ls output does not have color while SSHing to another machine with iTerm2, but does with Terminal

itermterminal

Just as the title says, when I ssh to my work Fedora server with iTerm2 I don't get color ls output. When I ssh to the same server with OS X's default Terminal app, ls color output works just fine.

EDIT: All other ls output is colorized properly. Both iTerm2 and Terminal display ls locally as colored, and Terminal works properly when SSH'd over to the work machine.

The only time I'm not getting colorized ls output is when I use iTerm2 to SSH to my work machine. Terminal produces colorized ls output when SSH'd to my work machine and so does PuTTY on Windows.

When SSH'd into my work machine from iTerm2 'ls -G' also makes no difference. Still no coloration on ls output.

Also, when SSH'd to my work machine from iTerm2, the only thing I'm not seeing color on is the output of ls. My prompt is colorized, vim works with color, and if I echo $TERM I see xterm-256color.

Any ideas?

Best Answer

ls output with colors (ls -G) is not the default option. Run the following command in your terminal to enable ls colors by default:

echo "alias ls='ls -G'" >> ~/.bashrc
source ~/.bashrc

This and all future terminal sessions will now display colors correctly.


If you're still not seeing colors on your remote (or local) session follow these steps:

In iTerm verify that you're sending a terminal type that supports colors. Open the preferences window -> Profiles -> Default -> Terminal. I'd recommend putting xterm-256color as the Terminal Type.

Terminal Preferences

While connected to the remote machine, run ls -G and open the iTerm preferences again: preferences window -> profiles -> Default -> Colors. Adjust the ANSI Colors, and turn the minimum contrast down until the colors in the terminal window start to show color.

Terminal Colors

If the remote system supports ls --color=always, remove any existing aliases in ~/.profile or ~/.bashrc and update as follows:

echo "alias ls='ls --color=always'" >> ~/.bashrc