SUDO previlages access for particular commands


#1

Hi guys

how to give sudo previlage user to access particular commands only execcuted
i am try this one but its not working

$ sudo vi /etc/sudoers
# # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Host alias specification

User alias specification

Cmnd alias specification

User privilege specification

root ALL=(ALL:ALL) ALL
pradeep ALL=(ALL:ALL) /bin/cp

Members of the admin group may gain root privileges

%admin ALL=(ALL) ALL

Allow members of group sudo to execute any command

%sudo ALL=(ALL:ALL) ALL

See sudoers(5) for more information on “#include” directives:

#includedir /etc/sudoers.d
~
“/etc/sudoers” [readonly] 31L, 798C 1,1 All

but this type not working


#2

ITS working fine but i am not giving the correct username , for the casesenstive problem we dont access the sudo , Now its working fine


How to give access to start,stop and restart a service like apache to a user
#3

HI

Always use visudo editing the file /etc/sudoers is not recommended, because the main advantage of visudo is it will prompt you an warning message if you did any syntax error with in the file.


#4

visudo keeps your original file and copy content of it under /etc
[/etc/sudoers.tmp]
visudo edits the sudoers file in a safe fashion


#5

i want to give the particular user to gain acess for the root privilages but only for certain commands like copying,removing,installing, shutdown. reboot like that,

if i give the line like
"usera ALL=(ALL) /bin/cp /sbin/shutdown /bin/chmod /bin/chown " only the first command /bin/cp is working rest of them are not working, can u tell whats the mistake i m doing, thanks in advance


#6

Hi
It shoulb be

usera ALL=(ALL) /bin/cp, /sbin/shutdown, /bin/chmod, /bin/chown


#7

Thanks raghu, i ll try this and one more doubt is that , how can i come to know for a particular command i should give /sbin/shutdown for shutdown, /bin/chmod for changemod like that, because there are many commands available in many directory example,
in /sbin many commands are there, /bin many commands are there and in /usr/bin /usr/bin many commands are there, how can i go and take the exact path for the command to execute, can u explain it???

Thanks


#8

If you want the absolute path of a perticular command, by using command whereis you can get the actaul path of the command like whatever you want

once look at the below screen shot

after on wards you can use below command for shutdown the system

#sudo /sbin/shutdown

#9

Thanks a lot, this is the thing i m exactly looking for ,

and one more thing is for a certain commands like reboot, we can find two paths, can we put any one of them, both of them behaves the same thing only

for example, for reboot im finding two command path ,
and the next thing is /sbin contains commands for the superuser
/bin comtains commands for the user
then what does /usr/bin or /usr/sbin contains???


#10

You can use any one of them, actually it has user version of poweroff, halt, reboot provided by usermode package.

You can shutdown, reboot the machine by using any one of the commands /usr/bin/reboot or /sbin/reboot as a root user or sudo user.

#sudo /usr/bin/reboot 
(or)
# sudo /sbin/reboot

#11

Thanks a lot raghuu , it works fine … :slight_smile: