Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save livealive7/29185b69eb77e36068b2c4da8e355937 to your computer and use it in GitHub Desktop.
Save livealive7/29185b69eb77e36068b2c4da8e355937 to your computer and use it in GitHub Desktop.
Shell script to modify the /etc/sudoers file and give sudo permissions for a user and also to turn requiretty off.
# Take a backup of sudoers file and change the backup file.
sudo cp /etc/sudoers /tmp/sudoers.bak
sudo echo "$USER ALL=(ALL) NOPASSWD:ALL
Defaults:$USER !requiretty
" >> /tmp/sudoers.bak
# Check syntax of the backup file to make sure it is correct.
sudo visudo -cf /tmp/sudoers.bak
if [ $? -eq 0 ]; then
# Replace the sudoers file with the new only if syntax is correct.
sudo cp /tmp/sudoers.bak /etc/sudoers
else
echo "Could not modify /etc/sudoers file. Please do this manually."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment