When I use the su command in OS X's Terminal — say, to quickly switch to an administrator account to mount a drive using diskutil — the style of the command prompt changes. Before using su, the Terminal's Darwin bash prompt displays my computer's name as dictated by the part of $HOSTNAME which precedes the part of that text string which reads .local, a colon, the current working directory, a space, the current user's name, and, finally, a dollar sign. After running su, all that's displayed is bash-3.2$. Is there a command that I could run to revert this without undoing my use of su?
2 Answers
Better idea might be to use sudo instead of su. The prompt change is important because it reminds you that you have elevated privileges and could easily accidentally break something, so you should be careful.
- I usually do this from a standard user account, and, at least in OS X and probably in most Unixes, these kinds of accounts aren't members of the
sudoersgroup by default. I'm OK if the prompt changes to reflect that I'm using a different user account, but I'd rather have the prompt's style remain the same. OS X's default prompt contains the name of the account you're currently logged into, so I think that should be fine.RandomDSdevel– RandomDSdevel2015-02-18 00:34:50 +00:00Commented Feb 18, 2015 at 0:34 - 1You could add yourself to the
sudoersgroup or edit the/etc/sudoersfile.Steve Wills– Steve Wills2015-02-18 00:46:39 +00:00Commented Feb 18, 2015 at 0:46 - Should a standard user be a member of the
sudoersgroup, though?RandomDSdevel– RandomDSdevel2015-02-18 18:39:27 +00:00Commented Feb 18, 2015 at 18:39 - Sure, why not? It's your way of telling the system you're not just a "standard user", you're a user who should be allowed sudo access.Steve Wills– Steve Wills2015-02-18 18:59:48 +00:00Commented Feb 18, 2015 at 18:59
- That makes sense, but I'm not sure if I'm comfortable with the idea of giving a non-administrator account the ability to use the
sudocommand. Doing so sounds like a security risk tantamount to just turning my standard user account into a full-blown admin one, and I don't like the idea of exposing my data like that.RandomDSdevel– RandomDSdevel2015-02-18 21:29:18 +00:00Commented Feb 18, 2015 at 21:29
Run su -l $USERNAME via Terminal to log in as another user without losing your current prompt style.
PS1inman bash$PS1is an environment variable. Runningecho $PS1without invokingsuoutputs\h:\W \u\$.