I have line in script which is working, but not working from command line.
echo "User ALL = NOPASSWD: ALL, !/bin/su" | sudo tee -a /etc/sudoers
[user@localhost ~]$ echo "test ALL = NOPASSWD: ALL, !/bin/su" | sudo tee -a /etc/sudoers
bash: !/bin/su": event not found
[user@localhost ~]$
Edit: I am trying to add a sudo user with no permission to su
command and sudo user have password less access to root using sudo -i
. I was just checking each command in that script, to see how they work in command line.
I found a workaround for this in command line, that I have to use "'!'"/bin/su
. So can someone help to explain why this didn't work in command line?
sudoers
file in this fashion instead ofvisudo
? second, it's wrong format - no need for!
. Third, it should beusername ALL = NOPASSWD: /bin/someprogram
, no comma. I've no idea what you're trying to do here, but it's wrong approach in the first place. If yourtest
user gets compromised, you basically give attacker access tosu
binary – Sergiy Kolodyazhnyy Jan 15 '17 at 07:25visudo
will work with script(will it work?).!
which I believe will negate the command followed by that and user won't be able to execute it. Edited question for clarity. – Panda Jan 15 '17 at 07:55/etc/sudoers
. It's a file that you, as the admin, should edit manually and carefully... withvisudo
. – Kusalananda Jan 15 '17 at 07:56sudo
either. Adding that line tosudoers
will give them root access throughsudo
, and the possibility to edit thesudoers
file themselves (if I'm reading it right). – Kusalananda Jan 15 '17 at 08:05su
does not give special powers to root. So preventing someone with root capabilities from using it is pointless. – ctrl-alt-delor Jan 15 '17 at 14:51