Create add-sudo.sh
file with command :
su root
nano ~/add-sudo.sh
Paste this content:
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Enter Username"
exit 1
else
USER=$1
sudo usermod -aG sudo ${USER}
if [ -f /etc/sudoers ]; then
sudo echo "File exists."
sudo echo ${USER}' ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
sudo echo 'add: "' ${USER} ' ALL=(ALL) NOPASSWD:ALL" in /etc/sudoers file'
else
echo "File /etc/sudoers does not exist"
exit 1
fi
fi
Make add-sudo.sh executable:
chmod +x ~/add-sudo.sh
Usage :
su root
bash ~/add-sudo.sh nolwennig
(NOTE: Change ‘nolwennig’ for Your username)
Add alias and Function in ~/.bashrc or ~/.zshrc
add-sudo() {
sudo /home/root/add-sudo.sh $1
}
Usage :
add-sudo nolwennig
(NOTE: Change ‘nolwennig’ for Your username)