What is su and sudo command in Linux & Why It’s Important to Use Linux Effectively?
Linux has lots of security features in place that are meant to safeguard your system from threats and sometimes from our own Mistakes or Stupidity.
To limit access on Linux system there are three main features are available:
- File Ownership
- File Permissions
- Root User Account
A System Admin can control system access as needed using these above three main features.
In this article we are going to discuss an important and mostly used command in Linux which is something called ‘SU’ ( Substitute User)
Substitute User command instructs the system to run commands on behalf of another user account which is root by default.
Linux Root User Account (also called superuser) offers higher privileges as compared to normal users and similarly in Windows operating system has the same concept of an administrator account.
- Let’s understand this concept in more simple way
â€œA normal user can only Delete, Modify and Read their own files, but can’t access other user’s files and have read-only access to the system files so they can use installed applications.‘
An administrator supposed to know more about what they are doing, they can make system-level changes without damaging or leaking sensitive data.
A normal user without administrator or root permissions can’t perform system level tasks, so there is a chance that they can break the system.
The Idea of Super User Account in Linux
Linux uses different approach to handle administrative rights matter. Instead of giving full privileges to a normal user account (as in windows OS you can assign administrative rights to a normal user).
Linux draws a line between super user account (also called root) and a normal user account.
The SU idea is, if you need to do something that requires administrative privileges, you can use â€˜suâ€™ command and accomplish a system-level task while you are logged in as a normal user account.
This idea reminds you that you are doing something more serious to your system as it won’t let you do it without using ‘su’.
Let’s know more about â’SU’ command.
The syntax of the ‘su’ command is:
su [options] [commands] [-] [username]
The square brackets indicating that the enclosed item is optional. So, the simplest way to use the ‘su’ command is to just type:
Linux System assumes that, in the absence of a username, the user wants to switch to a root session, and thus the user is prompted for the root password as soon as the ENTER key is pressed.
This produces the same result as typing:
- After providing correct password, the session will change ownership as root user.
‘SU’ Command’s Benefits
SU is usually the most expedient way to change the privileges level of a login session to root user.
It offers a safer way to perform administrative tasks on multi-user systems to use the system than to routinely log on as the root user.
Linux root account is extremely powerful, it can delete your entire system using a single terminal command, so it should feel like a big deal if you need to work with that.
‘su’ Vs â’sudo’
While using ‘su’ you have to share root user’s password with other users whereas ‘sudo’ make it possible to execute system-level commands without even providing root password.
‘sudo’ can delegates system responsibilities to normal users without sharing root password, you can use your own user password to execute system commands.
Using â€˜visudoâ€™ command in terminal we can add/remove the list of users who can execute ‘sudo’.
By following highligted syntax in below image, you can allow any user to execute system level commands using â€˜sudoâ€™ command.
Note: You must logged in as root user to execute visudo command.
Both tools are great as it’s safer way to perform system-level tasks and encourage fewer mistakes, but still it’s powerful and should only be used by right persons.
That’s all for now. Don’t forget to provide us your valuable feedback in the comment section or by sending us an email at firstname.lastname@example.org.