Created
October 23, 2015 23:45
-
-
Save buchireddy/19eb6593f692852d2df7 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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