I wanted to write a script to add some tools to my VPS or VMS and I write something like that
# Edit sudoers
echo -e "${GREEN}Configure sudoers...${NOCOLOR}"
echo
echo '# Allow user to use sudo without passwd' >> /etc/sudoers
echo '$USER ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
this script run as Sudo and i test echo $USER in Sudo is the user name, not root I mean I'm kind of new so I did not know that and write this but when I test it I'm getting error permission error
i don't know what to do I did some search but can't find anything
sudo
, the redirection is done by the parent process, which is unprivileged. Also, single quoting (echo '$USER...
prevents interpretation of$USER
. To demonstrate:echo $USER; echo '$USER'; echo "$USER"
. – waltinator Apr 01 '21 at 04:54sudo scripts
, the redirections inside will be done by the privileged shell which sudo ends up launching. – ilkkachu Apr 01 '21 at 11:33sudo echo ... > ...
is why you need to show what exactly it is you're trying to do. The full command line, and the associated error message. Just copy-paste them from the terminal, and [edit] your post to show. – ilkkachu Apr 01 '21 at 11:34