13

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?

Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113

2 Answers2

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:

Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113
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.

berry120
  • 10,924
  • 10
  • 51
  • 62