Use different profile for a specific Terminal


When logging into remote server with Terminal, I need to use different profile. Is there any way to make the Terminal displayed with different profile? Better still, is there a way to recognize the login access to display with different profile automatically?

Best Answer

By "Profile" I assume you mean the different profiles defined in the Terminal preferences under "Settings"?

If so, modify, duplicate, or create whatever profile you want to use when connecting to the remote server. Under the "Shell" tab of the profile, set the command to run to be whatever ssh command you give to log into the remote server. Uncheck the "Run inside shell". Now, whenever you open that profile under the "Shell" menu of Terminal, it will launch the remote connection. If you want even more automation, assign a keyboard shortcut for that profile in the Keyboard preferences of System Preferences.

Remote SSH Command in Terminal Profile

If you are looking to have this happen when you type an ssh command, there are two alternatives:

  1. Write a shell function to execute an osascript (AppleScript) prior to the ssh command (see this other answer).
  2. Use something like tput setab <n>; clear in your remote .bashrc file. See background coloring for values to use for n. Note that this will not persist if you embed escape codes in your prompt that reset colors or if you do something else that resets terminal colors. This will also linger after logging out, but that can be fixed with similar escape codes. It's not really changing the "Profile", but you might get the effect you are looking for.