Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Change your 'root' prompt for safety System
Thanks to Keith O. for this one...

If you occasionally use the terminal as root, you should consider using a different prompt when 'rooted' - this will help you remember that you are working as root, and hopefully prevent you from doing something that you didn't intend to do.

The first step is to create a file named .tcshrc in /var/root (this file could also probably be created as /var/root/Library/init/tcsh/rc.mine, but I haven't tried that). You'll be placing your prompt in this file, so that it gets loaded each time you start a root session. Here's what Keith O. placed in his root .tcshrc file:
set prompt="%{\033[32m%}%n @ %/ on $host %#%{\033[30m%}  "
This changes the content and color of the prompt, so that it differs from that of his normal user. If that looks completely foreign to you, that's perfectly normal! Read this hint for a general overview of prompt variables, including an explanation of the color codes, which should help clear things up (a little!).

You can experiment all you like in a terminal session - whatever you set as prompt will only last until you change it again or close the session. It only becomes permanent when you place it in root's .tcshrc file. Also read the referenced hint for setting your normal user's prompt. You can do some pretty neat stuff once you figure out the structure. For instance, this is my normal prompt string:
set prompt="%{\033[0;1;32m%}[%{\033[36m%}%t %n%{\033[32m%}%{\033[33m%}[space]
%c3%{\033[32m%}]%{\033[0m%}%# "
Note: Replace [space] with the actual space character, and enter on one line; broken for easier display. That prompt string leads to this prompt display:



The colors help the prompt stand out from the text that flows as the result of whatever command I'm running. Customizing your prompt string (for both your normal user and root) is a good way to make your time in the terminal more productive.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[5,937 views]  

Change your 'root' prompt for safety | 9 comments | Create New Account
Click here to return to the 'Change your 'root' prompt for safety' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Color Prompt
Authored by: Anonymous on May 17, '01 05:41:14PM


I can't



[ Reply to This | # ]
Can't what?
Authored by: robg on May 17, '01 05:49:48PM

What, exactly, can't you do?

-rob.



[ Reply to This | # ]
Can't what?
Authored by: Anonymous on May 18, '01 01:34:03PM

Sorry about that.
I could get the prompt to work if I drag and dropped the text into the terminal window. I created a .cschrc file in my home directory with your prompt. I got the same error message as a previous post. (Unmatched ". ) I wanted to color my prompt, so I would know if there was no color, then I am root.
Also, I got the color terminal to work, but I want to alter the colors. Do you know how?



[ Reply to This | # ]
Can't what?
Authored by: robg on May 18, '01 01:47:05PM

For the normal user, the file you want to put the command in lives in your Users directory, in /Library/init/tcsh/rc.mine. You can create the init and tcsh directories if you need to.

Make sure you're entering the above prompt as one line, not two, in the rc.mine file. I just compared what's listed here to my rc.mine file, and the lines are identical - except I've broken this one up to display on two lines.

-rob.



[ Reply to This | # ]
Problem encountered
Authored by: ibadr on May 17, '01 06:08:14PM

The change for root works fine thanks.
For my own user account I created a file .cshrc in my home directory and put in your suggested prompt setting.
When I create a new shell I get the following error:
Unmatched ".

Please advise.



[ Reply to This | # ]
Problem encountered
Authored by: robg on May 17, '01 11:38:57PM

Well, for the individual user, the suggested place to put them is in ~/Library/init/tcsh/rc.mine, but they should work in .tcshrc as well.

Check and make sure you have both the open and close quotes in the prompt string, for starters.

-rob.



[ Reply to This | # ]
custom root shell prompt are for wimps!
Authored by: Anonymous on May 18, '01 01:34:06PM

This is a philosophical stance, not technical. Having said that, I'd leave the root prompt alone. Putting all that stuff in encourages a certain amount of laziness and sloppiness that you should never have when working as root. Getting used to a customized prompt also messes you up if you ever have to do any work as root on another system that doesn't have your customizations. Heck, this even happens with Mac folks who aren't working on their own systems, especially if they have to deal with someone else's customizations. :-)



[ Reply to This | # ]
custom root shell prompt are for wimps? NOT!
Authored by: skab on May 21, '01 11:07:29AM

>custom root shell prompt are for wimps!

Just like safety belts or airbags. Well...

I disagree, it can't hurt to change your su-prompt to something that reminds you of being logged in as root. And if you say "if you're focused on what you're doing, you KNOW that you're logged in as root, if you ain't, just don't do it", you never had to change something in your system after hacking all night on some piece of code and fell into this kind of programming coma when you are sort of driving on auto-pilot...

Having said that, the maybe most elegant way of globally changing your prompt is using the xxx.mine files in /usr/share/init/tcsh, not a .tcshrc file in anyone's homedir. Put this "rc.mine" file in there:

if ($?prompt) then # For interactive shells only (ie. not scripts):
if ($uid) then
set prompt="(%n@%m:%B%/%b)%# "
else
set prompt="(%{



[ Reply to This | # ]
custom root shell prompts are for wimps!
Authored by: Anonymous on May 21, '01 04:17:51PM

If you are logged in as a normal user, Bourne-style shells use '$' as the default command-line prompt. C shell, tcsh (the default for OS X), and other derivatives use '%'. If you are logged in as the superuser, the prompt changes to '#'.

Of course, if you're not sure whether you are logged in as a normal user or as the superuser, use other commands like 'whoami' or 'id' to find out --- and don't trust the prompt!



[ Reply to This | # ]