DEV Community

loading...
Cover image for Administrative Access Commands On Linux

Administrative Access Commands On Linux

larymak profile image lary mak ・2 min read

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 Command syntax:su OPTIONS USERNAME

The su command allows you to temporarily act as a different user.

By default, if a user account is not specified, the su command will open a new shell as the root user, which provides administrative privileges.

After executing the su 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:~#
Enter fullscreen mode Exit fullscreen mode

As you can see the has changed and reflected to root@localhost switching from admin@localhost:. This means you are now logged in as a root user.

To logout and return to admin account use exit command, It will change back

root@localhost:~# exit
logout
admin@localhost:~$
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To execute the sl command with administrative access use the su to switch to the root account

admin@localhost:~$ su  -
Password:
root@localhost:~# sl
Enter fullscreen mode Exit fullscreen mode
  • The Sudo Command syntax: sudo [options] command The sudo command allows a user to execute a command as another user without creating a new shell. Like the su command, the sudo 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:

Check Out My Blogs Here where we talk more on TECH

Connect With me at Twitter | Insta | YouTube | LinkedIn | GitHub

Do share your valuable opinion, I appreciate your honest feedback!

Discussion (1)

pic
Editor guide
Collapse
peter279k profile image
peter279k • Edited

Just notice that normal users don't have the sudo permission to use sudo to get root privilege temporarily.

It should choose one of approaches to complete that:

  • Creating user sudoer file and it can be located on /etc/sudoers.d/ folder.
  • Letting specific user be added in sudo group on Linux Ubuntu/Debian distribution.
  • Letting specific user be added in wheel group on Linux CentOS/RHEL distribution.