Add current user to sudoers group

 #!/bin/bash


# Get the current user

current_user=$(whoami)


# Check if the user is already in the sudo group

if groups "$current_user" | grep -q "sudo"; then

  echo "User '$current_user' is already in the sudo group."

else

  # Add the user to the sudo group

  sudo usermod -aG sudo "$current_user"


  # Check if the user was added successfully

  if groups "$current_user" | grep -q "sudo"; then

    echo "User '$current_user' has been added to the sudo group."

    echo "Please log out and log back in for the changes to take effect."

  else

      echo "Failed to add user '$current_user' to the sudo group."

  fi

fi


Comments

Popular posts from this blog

Clearing DNS cache on vCenter Server Appliance

Start and stop services in vCenter Server Appliance

How to step by step in detail install ssh on cachyos