Tell iTerm 2 to change color when I’m root

iterm

I would like to tell iTerm2 to have red text whenever I'm root when logged into a server.

Note:

I'm not able to change any configuration on the remote server.

Best Answer

Not as part of the iTerm 2 configuration. iTerm has no way of knowing you've gone to root in a remote session -- it's not watching what you're doing that closely (and what you're asking it to figure out is actually really complicated to program).

You can create an iTerm profile that has red text on whatever background colour you want and you always use that profile when you're going to go to root on a machine. It requires no changes to the root environment on the remote machine. But it does require you remember to use that profile for your rooted session.

Edit: while digging around I found this interesting article that talks about how you can change the background image in iTerm to show the hostname of the host you've ssh'ed in to. Notice how it's all based around the environment in your client's Mac shell -- once you're on the remote machine there's not a lot iTerm can do. The changing of a tab title does appear to be controlled by $PROMPT_COMMAND, as set in the remote session's environment, but there appear to be no documented hooks in iTerm 2 that let you extend what iTerm does when it changes the tab title. Pity.

I tell ya: mad props if anyone can figure out how to do this. It'd be handy for sure.