12

I've followed a couple of tutorials on my RPi and a lot of commands start with sudo; what does it mean and what does it do?

  • 7
    This is a great question, I can imagine a lot of beginners wanting information on this. – berry120 Jun 14 '12 at 11:44
  • @berry120 yes but it would have been more suited to Unix/Linux SE because people run their Pi's on other OSes as well (I'm looking at you, RISC OS!) – evamvid Apr 6 '14 at 0:22
  • Whaaaat? Year-Old Question! make that 2 years! – evamvid Apr 6 '14 at 0:23
  • @evamvid This was one of the first example questions on RPi.SE... – Alex Chamberlain Apr 6 '14 at 10:13
21

sudo stands for Super User Do; it allows you to run as another user, usually the super user (root), to carry out administrative tasks, such as update the software, change filesystems, and start daemons.

root has the ultimate power and can run pretty much anything. It can, therefore, do a lot of damage to your system and in the worst case, you will have to start again.

You must always understand what a command is doing before you run it.

Why do we have sudo?

For security reasons, normal users can't do everything. It prevents you doing anything too bad by accident and prevents malicious users damaging the system.

Why don't we sign in as root when we want elevated permissions?

sudo allows administrators to control what commands each user can run as root. For example, your administrator may allow you to run apt-get as root, but nothing else. Furthermore, all commands run via sudo are logged in /var/log/auth.log.

Other Distributions

The default Debian image has sudo installed in advance, but others may not. You can often install it using the distributions package manager, or investigate other ways of gaining root permissions.

Arch

You can install sudo using pacman: run pacman -S sudo as root. You should then add a new user and disable the root account.

su

In Arch Linux (and other distributions that support it), you can use su (substitute user) command to assume the identity of any other user (including root). This means that all your future commands (in the current session) will have their permissions. However, you will require the their password and the commands you run won't, necessarily, be logged.

See also:

  • 1
    Do you think information on su might be useful to really complete the answer? – Alex L Jun 14 '12 at 14:38
  • Propose an edit under the Other Distributions heading? – Alex Chamberlain Jun 14 '12 at 14:41
  • Further to this, I tend to write "sudo bash" as soon as I load my pi to avoid having to type sudo all the time. This lets you run everything with super user privileges. This is obviously a little dangerous, but with the rpi there is little majorly bad that you can do. – phalt Jun 14 '12 at 15:50
  • 1
    This is a very bad habit to get into! – Alex Chamberlain Jun 19 '12 at 12:47
  • 1
    @phalt Why don't you just log in as root then? – Jivings Jul 27 '12 at 12:23
2

You usually use it to execute a particular command as root, rather than your current user. For security reasons the norm in the Linux world is for your main user to have limited privileges, and for you to switch to root whenever you need to do something you don't have privileges for (such as installing packages.)

Root is a bit like administrator in the Windows world - it's your ultimate "can-do-anything" user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.