Monday, April 22, 2013

Disable sudo privileges for user

If you want, user should not execute command with sudo.
To remove sudo permissions for user, follow the process.

1. Change the group of user. To see how to change the group of a user click here.

2. Do not define the group in file /etc/sudoers
     A group-name is started with symbol % in  /etc/sudoers
     Comment the line in /etc/sudoers
    #%group-name ALL=(ALL) ALL
Above line without comment gives sudo permission to all users of the group.
If you comment this line, no user of the group can use sudo while executing any command.

3. Now whenever user tries to run command with sudo, it says
 Error - username is not in the sudoers file. This incident will be reported.

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.