is there any difference between running an intensive task over sudo with the following commands?:
- nice sudo [intensive command here]
- sudo nice [intensive command here]
BTW this is for Linux 3.x.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
There's a difference, a crucial one.
If you want to decrease the process' priority, the order does not matter. On the other hand, if you want to increase it, you must put
Since you are running the command as a normal user (otherwise you would not bother with sudo at all), you can only decrease the priority of your command. But if you use
sudo first, you can increase it if you want.
If you run
nice sudo then the prompt for your password will also be niced, but since you'll spend far more time typing it, it really doesn't matter much.
As ThoriumBR noted, if you are lowering the priority, then the order is irrelevant, but if you want to raise the priority, then (since this must be done as root) you must use
Otherwise I can't imagine any real difference.
Using the 'principle of least privilege' you should only run a program with root privileges if it needs them, and then drop them again as soon as you don't need them anymore.
So yes, there is a difference, if there is an exploit for nice, an attacker could run code with the same privileges as the nice program.
Also, sudo resets your environment, so it migh thave side effects, try
$ echo 'echo $PATH' | sh /usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/jens/.local/bin:/home/jens/bin:/home/jens/.local/bin $ echo 'echo $PATH' | sudo sh [sudo] password for jens: /sbin:/bin:/usr/sbin:/usr/bin
So the 'nice' command you run via sudo might actually end up being a different binary.
$ which ash ~/.local/bin/ash $ sudo which ash [sudo] password for jens: which: no ash in (/sbin:/bin:/usr/sbin:/usr/bin)
If your sudo access is limited to certain programs (
bar, for example), then you won't have authority to run
sudo nice foo, but will be allowed to run
nice sudo foo.