We have multiple commands which deal with sensitive information like passwords, system hardware on Linux. By preventing regular users from executing these commands helps to protect the system. In order to gain administrative access and gain some of the privileged commands you have to be logged in as a root user.
List of Commands
The
SU
Commandsu OPTIONS USERNAME
Thesu
command allows you to temporarily act as a different user.
By default, if a user account is not specified, thesu
command will open a new shell as the root user, which provides administrative privileges.
After executing thesu
command a password is required.
As a security measure, the password will not be visible as it is typed, so you have have to type it correctly.admin@localhost:~$ su - Password: root@localhost:~#
As you can see the has changed and reflected to
root@localhost
switching fromadmin@localhost:
. This means you are now logged in as a root user.
To logout and return to admin account useexit
command, It will change backroot@localhost:~# exit logout admin@localhost:~$
To avoid executing any sensitive commands, we configure the Steam Locomotive command, the
sl
command, to require administrative access. If the command is executed as admin in this case, it fails:admin@localhost:~$ sl -bash: /usr/bin/sl: Permission denied
To execute the
sl
command with administrative access use thesu
to switch to the root accountadmin@localhost:~$ su - Password: root@localhost:~# sl
The
Sudo
Commandsyntax:
sudo [options] command
Thesudo
command allows a user to execute a command as another user without creating a new shell.
Like thesu
command, thesudo
command assumes by default the root user account should be used to execute commands.
NOTE: The
sudo
command can be used to switch to other user accounts as well. To specify a different user account use the-u
option.
sudo
provides administrative access for the execution of the specified command. This is an advantage as it reduces the risk that a user accidentally executes a command as root.
If You have read this far I really appreciate ๐, Help me to grow my community:
Connect With me at Twitter | Insta | YouTube | LinkedIn | GitHub
Do share your valuable opinion, I appreciate your honest feedback!
Check out my other Blogs too:
- Linux Commands (CLI) To Get You Started
- Why You Should Learn Linux
- Choosing The Right Python Framework for Web Development
- How To Get Started With Open Source Project Contribution
- Build A Random Name Generator Using Python
- How To Write A Good README File
See you in my next Blog article, Be Safe and Take care!!
Enjoy Coding โค