0

As usage of sudo is state of the art in Ubuntu to gain privileges and implied and obligatory in the default setup. Should code samples and sniplets in answers be prefixed with sudo if the command requires root privileges although the necessity of privileges is clear from the context (e.g. apt-get almost always needs privileges and I see sudo omitted in a lot of answers)? Are edits which add sudo in such a situation welcome?

Pro for adding sudo (iff necessary):

  • code becomes copy-pastable line by line

Cons:

  • answers are not compatible with changes to the authentication (if in 2192 Ubuntu no longer works with sudo, but another mechanism

A simpler form of the question: Should answers not prefixed with sudo which don't include a hint about necessary privileges (be it in the text, with # as prompt or however) and contain code which wouldn't work if typed into a terminal with copy-paste (e.g. https://askubuntu.com/a/436424/173287) be edited generally?

3
  • In that specific answer, every command needs to be run as root. At which point, few people will bother with sudo on every command.
    – muru
    Sep 23, 2014 at 8:10
  • 1
    The problem with not mentioning sudo is that you almost always get the reply "I tried it but got Access Denied?!"
    – bain
    Sep 23, 2014 at 11:13
  • Screw all this. We should start using pkexec.
    – muru
    Sep 23, 2014 at 21:06

2 Answers 2

3

If sudo is necessary.

I do use sudo for a single command. However, if you need to run a series of commands as root, I would just specify that "the below commands need to be run as root."

sudo is dangerous. It's best to not use it unless necessary (or you know how to not destroy a system).

0

NO!

There are very many cases where using sudo is either unnecessary or actively harmful and should be avoided. It is, unfortunately, characteristic of new users to just slap a sudo onto any command. This can often lead to issues (for example when copying files) and should not be encouraged.

Using sudo is not "state of the art". It is a tool that should only be used in specific instances and should never be used lightly. Admittedly, the specific question you link to does contain commands that need to be run as root. Note, however, that with the exception of the two apt-get commands, the OP has used # as the symbol for the prompt which is *nixspeak for a root terminal.

So, sure, if the commands really need to be run as root and the OP does not specify this, you could edit it. But you should always be very careful to only do so if sudo is absolutely necessary and not "just in case".

3
  • I edited the initial formulation of the question. It was confusing. I stated "if the command requires root privileges", though (as far as I'm concerned this is a yes/no question - if I'm mistaken there, please help me understand with a comment to the question). The idea was not to add sudo to every command in a snipplet - that's ridiculous, I agree. Good point with the #, I didn't notice that. Sep 23, 2014 at 14:46
  • 2
    @KarlRichter I realize, it's just that I've seen too many answers here using sudo when it's not needed. Since it is never dangerous to leave it and it can be dangerous to use it when not needed, I wouldn't recommend blanket edits. They should be done only when the editor knows what they're doing.
    – terdon
    Sep 23, 2014 at 14:51
  • In my understanding your answer implies that unnecessary sudo should be removed from answers (that's why I added logical iff as in if and only if to the title). Sep 23, 2014 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .