Score:0

visudo says that there is a syntax error

fr flag

I am using centos 8.So, my intent is to make the user manager to be able to run this command without the need to use sudo.

manager ALL=NOPASSWD: tar -czf /root/assignment/result/student-submissions-$(date +\%Y-\%m-\%d).tar.gz /root/assignment/report/main/

Here is the output:

/etc/sudoers: syntax error near line 122

line 122 is the 1st line in the above code.

Score:2
mx flag

I also get the syntax error when I run it on my system. I have done the following:

At the top of the sudoers file (under the "defaults" lines), add the following line (your command you want to run without password):

Cmnd_Alias TAR_COMMAND = /usr/bin/tar -czf /root/assignment/result/student-submissions-*.tar.gz /root/assignment/report/main/

The wildcard * I used in the file name, is there to ensure the command may vary when it comes to the tar.gz filename. This way you don't have to use date variables.

Now add the following line at the end:

manager ALL= NOPASSWD: TAR_COMMAND

Try if that works for you

PS: Always use the full path to your executable. When only using "tar", every binary called "tar" can run from any folder without password. use the full path to ensure you only are able to run /usr/bin/tar.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.