Forked from buchireddy/modify_sudoers_for_requiretty.sh
Created
August 12, 2021 01:44
-
-
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.
This file contains 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