0

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
  • 1
    look for PS1 in man bash Commented Feb 18, 2015 at 0:18
  • That says that $PS1 is an environment variable. Running echo $PS1 without invoking su outputs \h:\W \u\$. Commented Feb 18, 2015 at 0:31

2 Answers 2

3

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.

14
  • 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 sudoers group 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. Commented Feb 18, 2015 at 0:34
  • 1
    You could add yourself to the sudoers group or edit the /etc/sudoers file. Commented Feb 18, 2015 at 0:46
  • Should a standard user be a member of the sudoers group, though? Commented 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. Commented 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 sudo command. 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. Commented Feb 18, 2015 at 21:29
1

Run su -l $USERNAME via Terminal to log in as another user without losing your current prompt style.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.