sudo (short for superuser do) is one of those commands that anyone who has ever used Linux has had to use at some point or another. The closest comparison would be the “Run as Administrator” option in Windows—it runs a program with elevated privileges, allowing it to access otherwise restricted parts of the operating system. sudo does very much the same thing. sudo command on linux allows users to run commands with elevated privileges or as another user. That in and of itself makes it one of the de-facto commands that any Linux user should familiarize themselves with.
Why use sudo?
We could just log in as root and execute whatever command but we don’t want to do that as it is a massive security risk. sudo lets us execute elevated commands as if we were root
but as a more “restricted” normal user. sudo uses the systems’ security policy (groups) which determines who can & can’t run sudo. Obviously you need to be using a user that has permission
to use sudo. We can check if the user we are currently logged in as has sudo
permissions by executing the following in a terminal:
				
					sudo -v 
				
			sudo privileges you’ll be prompted for the password, otherwise you’ll get an error message, you can also run the groups command which will output all the groups your current user is a part of.
				
					groups 
				
			sudo group and on Redhat\Rocky\Arch you’ll see the wheel group. If you don’t see that group you’ll need to contact your system admin or if you are the admin you’ll need to use the usermod command to add yourself to the sudo group (which ironically you’ll need to have sudo permissions to use).
				
					sudo usermod -aG sudo linuxman 
				
			sudo.Dude where's my sudo?
sudo: command not found, worry not! You only have to install the sudo command to your system. This can be done in a few ways (no surprise) depending on your distro. In general the first step you’ll need to do is logout of your current user and switch to root so that you can install sudo.Debian\Ubuntu
				
					apt install sudo 
				
			RHEL
				
					yum install sudo 
				
			Arch
				
					pacman -S sudo 
				
			After sudo is installed and while still logged in as root, simply add your user to the sudo/wheel group as outlined above and you’ll be all set!
sudo Command On Linux Basics
sudo command simply type sudo followed by the command you want to execute with elevated privileges.
				
					sudo  
				
			sudo to update the system. For example, on Debian based distros you’ll need to use sudo in front of apt in order for the updates to actually be applied.
				
					sudo apt-get update 
				
			sudo will prompt you for your password and once authenticated, the command will be executed as a superuser with elevated permissions.Quick start sudo options
Editing a file as sudo
sudo permission to edit. The following command will open your default terminal text editor in an elevated state.
				
					sudo --edit /etc/fstab 
				
			Running a command as another
				
					sudo --user= --group=    
				
			
				
					sudo --user=linuxman --group=sudo groups 
				
			Run last command as sudo
sudo (only in bash, zsh, etc.).
				
					sudo !! 
				
			This one is fantastic for those times a command doesn’t run quite right the first time around.
Launch default shell as another
sudo can also launch a elevated instance of the default shell as any user on the system using the following:
				
					sudo --login --user= 
				
			Check sudo list
We can also check what commands a user has access to.
				
					sudo --list 
				
			sudo privileges:
				
					sudo --user=linuxman --group=sudo sudo --list 
				
			wheel as its sudo group name.sudo conclude
sudo, take precaution! Edit the wrong file or run sudo rm in the wrong place and your system is done for. Always double check your directory with pwd before running sudo commands and follow proper security protocols and you’ll have a happy, stable, secure system. 
				 
								











