sudo problem

Issues related to applications and software problems
Post Reply
eric2kwok
Posts: 13
Joined: 2015/10/23 16:16:04

sudo problem

Post by eric2kwok » 2018/04/04 00:10:29

I encountered problem from sudo, when I input this command 'su -c 'echo eric ALL=(ALL) ALL >> /etc/sudoers'
Password:
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `echo eric ALL=(ALL) ALL >> /etc/sudoers'

What can I do? How can I use sudo without need to input the root passwords or user passwords

I hear that visudo command can do this, but how to do that?

I searched many web site from www.google.com, but no one was helpful.

Any suggestion would be welcome. Thanks in advance!

pjsr2
Posts: 614
Joined: 2014/03/27 20:11:07

Re: sudo problem

Post by pjsr2 » 2018/04/04 10:17:18

If you intend to delegate root powers to a user and give that user permission to run any command with sudo, add this user to the group named "wheel". You can find the powers of the "wheel" group given in the /etc/sudoers file

Code: Select all

usermod -a -G wheel user_name
You should avoid to change the /etc/sudoers file. It's contents may change when the containing package is updated. If you want to add some sudo permissions, put that in a file in the /etc/sudoers.d directory. Any file in that directory is appended to the contents of /etc/sudoers . Files in /etc/sudoers.d should be owned by root and writable only by root.

'(' and ')' have special meaning for the shell. Anything between these two characters is executed in a sub-shell.
You can avoid this by adding some double-quotes:

Code: Select all

su -c 'echo "eric ALL=(ALL) ALL" >> /etc/sudoers.d/erics_sudo_grants

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: sudo problem

Post by TrevorH » 2018/04/04 10:20:32

And whenever you change sudoers you should use the visudo command to do so as it syntax checks the file before it saves it so you cannot break it (if you have a syntax error in the file then sudo fails to work at which point you cannot edit the file to fix it...). If you edit a file in /etc/sudoers.d then use visudo with the -f switch to point it to the file you are editing there.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply