🎯Introduction to Linux Users🐧🐧🐧

🎯Introduction to Linux Users🐧🐧🐧

In these tutorial I will demonstrate about root, how to become another user with the su command and how to run a program as another user with sudo.

🐧root user

root user, also known as the administrator or Linux Superuser, is the most powerful entity(account) in the Linux universe. It is a special kind of user account that holds all kind of privileged that are necessary to perform administrative tasks, accessing all commands and files and many more. They can, quite literally do anything, nothing is restricted or off-limits for root.

🤔Is log in as root all time a good idea ???🤔

  • root user have full privileges over the entire system, can do anything and the system will not ask "if you are sure to perform this activities" ,i.e. if you'r inexperienced user then mistakes made by you can be catastrophic even leading to delete your entire system.

  • Every hackers know that there is a root account and they can execute code remotely and gain access to root to breach in.

  • Running as root by several users leaves no record who did what and who is responsible for what. So to have clear accountability and responsibility mapping users should use different accounts.

Due to above consequences of running as root, most of the modern Linux distros won't let you login as root. The less time you spend logged in as root, the better. So, its a best practice to use the root account exclusively only for administrative purposes and normal or regular users for rest of the tasks.

🐧The sudo Command

Log in as root user gives full permission on the entire system, to perform any tasks and the mistakes made by them can lead to any sort of damage to the system. Besides protecting yourself from disasters arising from running as root user, if you can’t log in as root then how do you administer your Linux system.

Well, that’s what the sudo command is for. The sudo command allows a regular users to perform the tasks that a root can do by providing temporarily root's power to user. It doesn’t require the root user to log in.

With sudo , user need to authenticate using their own password. The “/etc/shadow” file contains sensitive information such as the user's logging password, last changed password .

The sudo command used to mean “superuser do” or “substitute user do” that runs without a need to change your identity. To continue running commands with root power, you must always use the sudo command.

🐧How a sudo command works in Linux?

When a user runs a command with sudo, the system will checks that user permissions in the /etc/sudoers file. As this file contains a full list of users and the commands that can be run with sudo.

Now If the user is listed in the sudoers file and the command they are trying to run is allowed, the system asked the user for their own password. Once the user enters their password, the system checks whether the user's password was stored in the system's database. If the password is correctly matched, then command is executed with the privileges of root user.

The sudo command is useful for granting temporary privileges to users for specific tasks, without giving them full access to the root user account. This helps to secure the system by preventing users from making accidental or intentional changes to the system as the root user.

🐧🐧🐧let's try to understand by an example, say the user ankita wants to install "nginx".

here you can see its asking whether ankita is root??? user ankita don't have superuser privileges, so can't able to install nginx.

now let's try with sudo command,[ As sudo command is useful for granting temporary privileges to users for specific tasks]

but here it showing "ankita is not in the sudoers file". so ankita should be added in sudoers file.

As details of sudo is present under /etc/sudoers , we can edit the above file using #visudo.

To add user ankita to the /etc/sudoers files, we’ll be using the visudo editor: so that ankita have all superuser privileges. Now you can try installing nginx by using sudo command.

voila! nginx install by user ankita. 🐧🐧🐧🐧🐧

🐧SU

In Linux , user can have root privileged using sudo keyword. The snag with sudo is that you have to use “sudo” at the start of every command. If you’re just typing one or two commands, that’s no big deal. However sometimes it becomes a tedious act when you are doing specially administrative tasks or want longer sequence of commands to execute, it can become tiresome.

The su command used to mean “switch user” or “substitute user” that basically switching to a particular user and you need the password for the user you are switching to.

🐧How a su command works in Linux?

When a user runs the su command, they are asked for the password of that user account they are trying to switch to. Once the password is entered, the user is logged in as the target user and can execute commands with that target user's privileges.

For example, if a user wants to switch to the root user account, they can run the command su root and enter the root user's password when prompted. This will allow them as the root user and allow them to execute commands with root privileges.

📌whoami

this whoami command tells you your current user's username.

📌su to another user

"here the command su ankita helps the user to switch to ankita, that means ankita must be present in the system's database, then only it will switch to user ankita."

"here whoami commands tells that the current user is ankita".

📌su to root

The su root commands enable you to become root only if you know the root password.

🐧How to exit as a current user from shell??

$ exit

by using exit command user can exit from

🐧Conclusion🧑‍💻

Though we came to end of this article and I hope this article has helped you to understand about root, when to use su and when to use sudo command in Linux.

Hope you like this article. So Stay Tuned for the next article .

Thank you. Happy learning!📍

🐧🐧🐧🐧🐧🐧🐧🐧🐧🐧🐧🐧🐧🐧🐧🐧