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

Solution 1:

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

Solution 2:

I had the same problem. I found that the color theme I used in iTerm (solarized) redefined the colors ls used on the ssh host making them impossible to tell apart.

You can try the following to check whether it's not the case for you:

LS_COLORS="di=07;31" ls    # this will list directories as black on red 

If this does show colors, you might need to redefine colors on the linux machine. The following command defines (some) ls colors to be similar to the OS-X defaults:

LS_COLORS="di=00;34:ln=00;35:so=00;32:pi=01;33:ex=00;31:bd=00;34" ls

To edit the colors on linux, see the dircolors man page. You can also read the following on how to set colors from .bashrc: https://github.com/seebi/dircolors-solarized#installation