4 ms·
I sudo su very frequently because I'm almost always executing more than one command as root. Standard warnings apply, but my approach for being sure that I am w
by kwantam 15y ago
I sudo su very frequently because I'm almost always executing more than one command as root. Standard warnings apply, but my approach for being sure that I am who I think I am is to put my username in my prompt and color code it so that when I'm root the username turns red.
I also color code the hostname so that I can tell at a glance what machine I'm on.
For example,
export PS1='[\[\033[1;34m\]\u\[\033[0m\]@\[\033[1;30m\]\h\[\033[0m\] $newPWD]\$ '
where $newPWD is a friendly, shortened $PWD.
On that same machine, the root prompt is identical except that the color is set to 1;31m instead of 1;34m, which makes it bright red.
- silvestrov 15y agoNo need for 'su' to get a root shell. You can use 'sudo -s' for that, and you still set a root-specific PS1 in the bashrc file.
- thwarted 15y agoThis doesn't always run the same rc scripts (depending on the shell and local convention). I'm used to typing sudo su - (with optional username) to get the environment as close as possible to what it would be if I logged in as the target user.
- deleted 15y ago[deleted]
- silvestrov 15y agoalias ssu='sudo /bin/bash -login'
- pilif 15y agosudo -s launches a shell in non interactive mode (which goes through .bashrc or .zshenv and .zshrc depending on your shell) whereas sudo -i emulates a usrer login which puts the shell in interactive mode (.profile, .zshenv) Also -i does more stuff to simulate a login like setting $HOME and cd'ing there. Usually you might want to use sudo -i or 'su -' which both simulate a login. But sudo su - really isn't needed any more since -i has been added
- thwarted 15y agoOld habits die hard.
- jeza 15y agoI have generally found the difference between a $ and # prompt sufficient enough. I guess colours can't hurt though.