Root vs. Non-privileged Users. Getting Root Access (sudo, su, passwd):

πŸ‘€ Root vs. Non-privileged Users

Linux has two primary types of users:

  1. Root (Superuser) - The most powerful user with absolute system privileges.

  2. Non-privileged (Normal) Users - Regular users with limited access.


⚑ Root Privileges

Root can:

  • Run any command

  • Access any file on the system

  • Install/update software

  • Manage user accounts

  • Administer services

Warning: Avoid using the root account for regular tasks (e.g., browsing the web, writing documents) because a small mistake could damage the entire system.


πŸ” Non-privileged User Restrictions

Non-privileged users:

  • Cannot perform administrative tasks (e.g., installing software, creating users)

  • Limited to their own home directory

For administrative tasks, sudo or su is used to temporarily gain root privileges.


πŸ› οΈ Ways to Gain Root Access

1. Using sudo su

  • sudo (Super User Do) allows a user to run commands with root privileges.

  • su (Substitute User) allows switching to another user (typically root).

Steps:

sudo su
  • Enter your user password (not root's).

  • A new shell with root privileges starts.

  • Run administrative commands.

2. Using sudo Directly

  • Prefix a command with sudo to execute it as root:
sudo command
  • Enter your password.

  • The command runs with root privileges.

Example:

Running a command without sudo might give a "permission denied" error:

groupadd mygroup

Now using sudo:

sudo groupadd mygroup

πŸ”’ Password Caching in sudo

  • After running sudo, credentials are cached for 5 minutes.

  • You don’t need to re-enter your password during this window.

To reset the cache:

sudo -k

πŸ“ Changing the Root Password

  • By default, root account access is locked on distributions like Ubuntu.

  • To unlock it, set the root password:

sudo passwd root

Now you can use su to temporarily become root:

su
  • Enter the newly set root password.

🏠 Understanding the Root Directory

  • Root Directory /: The top-level directory of the Linux file system.

  • Root User's Home Directory /root: This is the home directory for the root user.

  • Non-root User's Home Directory /home/username: Home directories for normal users are created here.

Updated on