sudo command stands for “Super User Do”.
sudo command works
When setting up a Linux system, two types of users are usually created:
- root user: - superuser, can add/remove new users and perform privileged/administrative tasks
- normal user: this is the default user with fewer privileges
It’s a common safety measure to use a Linux system as a normal user than using as root. The reason is, mistakes can happen anytime. With
sudo, we can prefix a command to request to run this command as a superuser.
sudo is used before a command that requires root privileges to be run for example, when updating the apt-cache in Ubuntu:
sudo apt update [sudo] password for nmurgor:
Or updating the system in Arch/Manjaro:
sudo pacman -Syu [sudo] password for nmurgor:
Notice how this requests your password. The password requested is a confirmation from you to execute the command prefixed with
Typing your password and pressing enter executes the command if the password supplied is correct.
When to use the
- Installation of software packages with package managers like apt-get or yum.
- Editing system configuration files, such as /etc/passwd, /etc/group, /etc/shadow.
- System updates or upgrades with package managers like apt-get or yum.
- Starting or stopping system services, such as Apache or MySQL.
- Creating or modifying system-level directories, such as /usr or /var
When not to use sudo:
Running commands that do not require administrative privileges: Using sudo unnecessarily can potentially harm your system, so only use it when it is necessary. If a command does not require administrative privileges, running it with sudo is not necessary and can potentially cause issues.
Running commands from untrusted sources: If you are not sure whether a command from an untrusted source is safe, you should not use sudo to run it. Running such commands with sudo can potentially give the command elevated privileges and can harm your system.
When you are not surewhat the command does before using sudo to run a command, make sure you understand what the command does and what its potential impact on your system can be. If you are unsure, it is better not to use sudo and seek help or more information.
When executing a command that modifies sensitive system files:If you are running a command that modifies sensitive system files or configurations, you should be sure that the command is safe and necessary before using sudo.
Unnecesssary use of
sudocan be catastrophic. One might end up with a broken file system with some files and directories being “read-only” for a normal user and other undesirable side effects.
Found this article helpful? You may follow me on Twitter where I tweet about interesting topics on software development.