Monday, April 22, 2013

Add username & group in sudoers file

Error - username is not in the sudoers file. This incident will be reported.


Open the file /etc/sudoers, Add following line in it
username ALL=(ALL) ALL
If your username is john, the line should be
john ALL=(ALL) ALL

If you want to add whole group as sudoers.
%group-name ALL=(ALL) ALL
where % indicates the name is a group.

If your group-name is wheel, the line should be
%wheel ALL=(ALL) ALL

Run multiple commands in Linux Launcher

If you want to run multiple commands in launcher.




Example:- If you want to stop apache2 (httpd) & mysql (mysqld) simultaneously. You would use 

service apache2 stop && service mysql stop
or
service httpd stop && service mysqld stop

But unfortunately it won't work in Launcher. It runs the first command but does not execute second.

To run multiple commands as a Launcher, you should use
sh -c "service apache2 start && service mysql start"
Now when you run launcher, it executes all commands.

If you want to run three commands,
sh -c "service apache2 start && service mysql start && cat > redirect"
In above example, it would start both services as well as create a file redirect.

Run sudo without asking user password

No password for sudo


Open file /etc/sudoers  and uncomment following line.
%sudo ALL=NOPASSWD: ALL
Save the file.

Now if you run commands with sudo, it does not ask user password.