I use iTerm2 in Mac, and frequently access Linux machines through ssh. I find that the color schemes (e.g. the colors in the output of ls, grep, emacs, vim) are always slightly different between Mac and Linux via ssh.
I am aware that one can set the color scheme by changing Colors in the current iTerm2 profile. When I modify the color scheme this way, the colors change in both Mac and Linux, but they are always slightly different from each other. It appears that the Mac color scheme always match the scheme set in iTerm2, but the Linux scheme is always a bit different (example below).
I would like to understand how to make the colors appear exactly the same on Mac and Linux via ssh. I've found many related questions with very specific solutions (e.g. modify environment variables), but haven't found a clear explanation of how the color displayed on the screen is actually determined in iTerm2 when various commands/text editors are run with and without ssh. Thus, I'd like to know what any proposed solution is actually doing instead of just fixing my problem. Direction to explanatory resources would be great.