Adding a user to the sudoers file for Sudo

  • Thread starter Deleted member 67029
  • Start date
For the typical sudo functionality (run one command as a different id, typically root), I've switched to doas. I like it, the setup and configuration is easier. But I understand SirDice's concern about the "achilles' heel", and for actually getting a root shell (what one typically does with "su", or "sudo ...sh"), I would like to be prompted for the root password. Haven't figured that one out yet.
 
ralphbsz you mean if you
doas sh

you want to be prompted for the root password? I think that's what you're saying, I just want to make sure. I don't have an answer, just clarification.
 
The way sudo is known today belongs to "Ubuntus sudo configuration" and use case; Even this thread just assumed that sudo has to be configured to get a user as mighty as root with its own password. But before Ubuntu was born sudo was used to let specific users execute specific commands as another user (which can be root, but mustn't), f.e. to enable a user (or a whole group) without root privileges to perform a reboot (and that maybe without the need for a password) etc. Also it assumed that sudo is the tool for administration a unixoid system (su - is sometimes even unknown to younger folks); Meanwhile doas was named (which I prefer & use sometimes), but also super exists.

IMO the question of the OP cannot be answered because it's missing any hint of what's the goal of this sudo configuration.
 
Being used to both of them by now, I find sudo and doas equally easy or difficult. Using sudo is a bit more convenient because the persist option of doas isn't, as far as I know, yet working on FreeBSD.
 
  • Like
Reactions: mer
It's often muscle memory: you type sudo and get "command not found" or "doas" and get the same message while you go smack your head on the desk.
 
To get sudo privileges on Ubuntu or LM, all I had to do was add the user to the "sudo" group. I don't know if that works on FreeBSD because I don't install sudo on FreeBSD. Never liked sudo much, and consider it an unecessary security risk. Would uninstall it on Linux if I ever wanted to use Linux for anything serious, but I don't, so I haven't bothered with it.

On Linux installs, one of the first tricks I learned was sudo passwd so I can then change the root password to something I know, and quit using sudo in favor of using su.
 
To get sudo privileges on Ubuntu or LM, all I had to do was add the user to the "sudo" group. I don't know if that works on FreeBSD because I don't install sudo on FreeBSD.
Uncomment this line in sudoers:
Code:
## Uncomment to allow members of group sudo to execute any command
# %sudo ALL=(ALL) ALL
 
An obvious comment, if you think the root password is important perform an "pkg uninstall sudo".
You can actually configure sudo(8) to ask for root's password instead of the user's password.
Code:
     rootpw            If set, sudo will prompt for the root password instead
                       of the password of the invoking user when running a
                       command or editing a file.  This flag is off by
                       default.
sudoers(5)

And, this might be obvious, take care who you assign privileges to. It's tempting to just go ALL=(ALL) ALL, that's fine if it's your own system, not so great if you only need to allow specific users some limited access to restart a service for example.

I have been using doas. Which is better?
Never actually used doas(1) but I don't think one is better than the other. sudo(8) is more commonly used, and has been for a long time, so there's plenty of tips, tricks and pitfalls to find for it. doas(1) is more like the new kid on the block.
 
An obvious comment, if you think the root password is important perform an "pkg uninstall sudo".
I've never actually tried that (yet), but it might be worth mentioning that, before doing so, we should probably use sudo passwd (i.e., sudo passwd root), to change the root password to a password we know, to avoid hamstringing ourselves.

When I first started using Mac OS X I was scared to death of sudo, not understanding it well, not knowing the root password, and being so accustomed to using the root password in conjunction with su.

When I want to do something "sudo-like" there is always su -m, i.e., su - m root, which gives you an id=0 without changing your SHELL or HOME directory. To that end, I usually modify .shrc (or, in Linux-land, .bashrc), to change the command prompt suffix from "$" to "#", with an if... then... else... statement, like the following:
Code:
if [ "$(id -u)" = "0" ]; then PS1="(\u@\h \w)# "; else PS1="(\u@\h \w)$ "; fi
 
When I want to do something "sudo-like" there is always su -m, i.e., su - m root, which gives you an id=0 without changing your SHELL or HOME directory.
Why I always switch to root with su - (means: "want the complete root environment"): As long as you're working with some command line tools everything is okay, but if you're using f.e. something like Midnight Commander: If your user hasn't started it before you'll get configuration files owned by root inside the users home directory. Such things can have strange effects (f.e. a user unable to use and/or configure this program). Or if the config is present:
Code:
jo@freya ~>  /usr/bin/su -m tester
Password:
tester@freya ~>  whoami
tester
tester@freya ~>  echo $HOME
/home/jo
tester@freya ~>  mc
Failed to run:
Cannot create /home/jo/.local/share/mc directory
tester@freya ~>
 
Why I always switch to root with su - (means: "want the complete root environment"): As long as you're working with some command line tools everything is okay, but if you're using f.e. something like Midnight Commander: If your user hasn't started it before you'll get configuration files owned by root inside the users home directory. Such things can have strange effects (f.e. a user unable to use and/or configure this program). Or if the config is present:
jo@freya ~> /usr/bin/su -m tester
Password:
tester@freya ~> whoami
tester
tester@freya ~> echo $HOME
/home/jo
tester@freya ~> mc
Failed to run:
Cannot create /home/jo/.local/share/mc directory
tester@freya ~>
Good points. I don't use Midnight Commander, and in general don't use root to run anything unless it's absolutely necessary. Want to see the "#" command line suffix mainly to remind myself to type exit as soon as possible, and to deliberately lose the root privileges just as soon as they're no longer needed for what I'm doing. Using su -m mainly to preserve the present working directory; sometimes prefer to use something like cd path; su - m root -c "tar -xzpf sometarfile.tgz" just to save myself from having to remember to type exit.
 
Want to see the "#" command line suffix mainly to remind myself to type exit as soon as possible
I'm also working with the prompt:
prompt_root.png

For root I'm always use a red colored prompt to be warned what I'm doing and where I am.
 
Very nice. I don't use color prompts, but ()=FreeBSD, []=Linux, {}=Mac OS X, and hostnames can also be informative:

Screenshot at 2021-07-07 13-32-46.png


I don't feel my ways of doing things are superior or the only ways; they're just old habits developed after decades of working with different systems. I appreciate this forum as a great place for sharing different ideas. Thanks for sharing!
 
My regular user prompt is green, my root zsh prompt red,
/root/.zshrc
Code:
autoload -Uz colors && colors
autoload -Uz promptinit && promptinit # Advanced prompt support
prompt off            # disable default prompt
setopt PROMPT_SUBST   # Allow custom prompt
PROMPT='$fg[red]HOST:%n: $fg[default]%d #'
 
Screen Shot 2021-07-07 at 1.13.39 PM.png

I like the trick with color-coding both the prompt and /etc/motd; since I often have dozens of terminal windows on my desktop, I can tell at a glance which machine is which. If your prompt looks relatively normal, you are working on a relatively normal machine. If it has a colored or shaded background, you're at a machine that usually doesn't do logins. And if the prompt is red, you are logged in as root.

Observe that I have converted to doas, except on some Raspberry Pi's I haven't finished that task yet (still need to use sudo to get a root shell).
 
Another advantage of su -m is that it will preserve all environment variables. Maybe sudo and/or doas can do that too. I don't know, and am content to use su -m. Yet another advantage? Ready-to-go right out-of-the-box, without installing any additional software on FreeBSD, Linux, or Mac OS X.
 
Back
Top