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


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

2 Answers 2


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.

  • Isn't Xresources only for X? This sounds like a purely command line task. Mar 7, 2011 at 18:25
  • Good question. I thought colour settings would propagate if the remote login device said it was type xterm but I'm trying it now and it's not working. Edited the answer and thanks for pointing that out. OP: if you can do X forwarding you can launch an Xterm on the remote machine that's coloured to indicate it's a root Xterm session using the .Xresources approach.
    – Ian C.
    Mar 7, 2011 at 18:57
  • 1
    Well iTerm2 is displaying the current user@host in each tab. I was hoping there was a way to use that info to modify the text.
    – Nifle
    Mar 8, 2011 at 8:27
  • The problem lies in that you want an action to trigger (changing the terminal colours). I don't think iTerm 2 has hooks in to these things. Yes, it can change the tab bar title, but you can't extend that hook with generic AppleScript or any such thing.
    – Ian C.
    Mar 8, 2011 at 15:11

I really don´t understand why you say you can´t change any configuration, yet you´re able to use the root user…

But anyway, you could run the following line every time you log in to your remote server, which will color your prompt red (and show it as "root@hostname | /current/directory" , once you´re root´ed with sudo -s:

export SUDO_PS1='\[\e[41m\]\u @ \H | \[\e[7m\] $PWD \[\e[0m\] \n > \[\e[0m\] ' 

Assuming the remote server´s sshd configuration has PermitUserEnvironment set to "yes", you could hand the PS1 over when you instantiate the ssh connection, something along the lines of (haven´t tried this, though):

ssh user@server -t "SUDO_PS1='$SUDO_PS1'; exec bash"
  • Well Not able Isn't techically correct. 1. Just because you can do something as root does not mean that you should. 2. I'm not the only one working on these servers and perhaps they dont care for the same colors I do. 3. If I do it once in iTerm I don't have to do it for each of the 25+ servers I work on.
    – Nifle
    Mar 8, 2011 at 8:29
  • 1
    I hoped you (and your colleagues) are not logging in as root, but rather as (admin) users that are listed in the sudoers file; then the custom SUDO_PS1 will only be available for you, and you could even put it into the remote .bash_profile. Even if you ssh directly as root, you´ll be able to set SUDO_PS1 temporarily for this session with the exec command I´ve mentioned above (and unless you and your colleagues work in the same screen they won´t notice). You could think about incorporating this in a bash alias for easy access to your 25+ servers.
    – Asmus
    Mar 8, 2011 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .