36

In a comment here I've been told that unnecessarily using sudo should be avoided. While it wasn't needed in that particular case, I don't see any harm in using it.

I think that when executing trivial programs like cat as root using sudo, the overall risk of hitting a bug that would somehow compromise system security is very low.

So can someone please point out the possible implications, besides typing 4 more characters and a space?

Jan
  • 12,931
  • 3
  • 34
  • 39

6 Answers6

71

The risk of a typo is more than the risk of a bug.

The risk of gaining a habit of "it doesn't work, stick sudo on it!" is much higher than the risk of a bug.

As a sysadmin who's seen people execute all sorts of random commands with sudo that didn't need them, I always caution against superfluous usage of sudo.

While cat isn't harmful, the habit that this encourages is.

Pandya
  • 37,289
muru
  • 207,228
15

I think there is another issue not yet mentioned: sudo status is cached for the shell with a default of 15 minutes. This means you don't have to provide your password in the next 15 minutes in order to execute a potentially dangerous command.

I think we all can think of more or less likely security issues that could result from that: Unknown software bugs that exploit this or forgetting to lock the screen with random people or co-workers around come to mind.

This is indeed my primary reason for not using sudo when I don't have to and even if I have to, for frequently closing shells after I'm done with sudo work.

musiKk
  • 281
9

Using sudo excessively is the Linux equivalent of the old Windows habit of running everything under the Administrator account. That one has been discussed and criticized to hell and back, so you can read everything that talks about why a person should not be running their Windows computer as an Administrator, and every single point will apply to habitual use of sudo on Linux.

SaltyNuts
  • 191
  • 2
4

well, it's just cause you might accidentally mess with sensitive parts of your file system, causing much much trouble to yourself Being careful is never enough, so better not to expose yourself to unnecessary dangers

ed0
  • 368
-1

When you do anything with Sudo, it means you give full rights to it, that's root access which is sometimes become very risky, if inadvertently, an app, which is running with root permission could do something wrong, results in a system crash to the corruption of the OS. Anyhow, for Cat, it's fine with root.

-2

There is nothing wrong with unnecessarily using Sudo. Sudo (in it's default configuration/purpose on Ubuntu) provides fully elevated privilidges. If a user has been granted those privilidges, they are his to exercise as he wishes (including unnecessarily!). However, using Sudo when it isn't needed raises the stakes. It's an unnecessary risk. A simple typo can become disasterous, and that is why most people avoid using elevated permissions when they aren't needed. However, just because it is common practice to avoid unnecessary Sudo usage, doesn't mean it's wrong to go a different way. Sudo to your heart's content!

Within the context of AskUbuntu, I'm not at all surprised that you were instructed to avoid unnecessary Sudo usage. The purpose of this site is to allow experts to ask questions and get expert responses, but in reality there are lots of novice users on here, who know just enough to get themselves into trouble. It's common for posters to try and protect these users from themselves. Sudo abuse is common among novice users, because they don't really understand what is or does, nore take the time to learn. Also, this site prides itself on producing quality content. Unnecessary commands are inefficient, and therefore reduce the quality of a post.