Operating System - Linux
1819874 Members
2864 Online
109607 Solutions
New Discussion юеВ

How to execute command in root as other user account?

 
SOLVED
Go to solution
Kenneth Leung_2
Frequent Advisor

How to execute command in root as other user account?

I was developing an operation menu script for our operation team to handle some application restart. The operation team only has the "oper" user account", but the command to restart the application require root privileges......

To prevent disclosing root password to the operator, how to execute a command in root as other user account? Pls help. Thanks
7 REPLIES 7
Alexander Chuzhoy
Honored Contributor

Re: How to execute command in root as other user account?

sudo utility will do the work.
First:
execute visudo (tool that edits the /etc/sudoers file) and add appropriate entries- read man sudoers first.
then you'll have to prefix the commands with sudo:
sudo reboot (for example).
g33k
Valued Contributor

Re: How to execute command in root as other user account?

you can set suid bit to that program. and give group oper right to execute it, it means that oper have right to execute this program, but process will run with root context.

for more help pls. read man chmod
Ivan Ferreira
Honored Contributor
Solution

Re: How to execute command in root as other user account?

For this case, SUDO is your best option. Sudo is normally already installed on most linux distributions. You only need to configure it. As root, run visudo to edit the /etc/sudoers file. Add something like this:

oper ALL = (root) NOPASSWD: /path/to/your/script


This entry will allow the oper user, run without entering a password, the script specified.

You can create a better configuration with Aliases, this is the most basic entry.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Kenneth Leung_2
Frequent Advisor

Re: How to execute command in root as other user account?

Thanks all...Another question is, I would like to force the operator to have only access to the menu script. I add the following line in the .bash_profile.

/path/my_menu_script.sh
exit

I hope that when the operator exit the script, they will be automatically logout.

However, I found that a ctrl-c in the menu script can break the operator into a shell & allow them to key in command......

How can I restrict the access of the operator like this? Please help. Many thanks...
Bob_Vance
Esteemed Contributor

Re: How to execute command in root as other user account?

man trap ( a built-in in the shell

Try

trap exit 1 2 3
/path/my_menu_script.sh
exit


This will cause him to exit when he sends a signal 1 , 2 (ctl-C), or 3.

kill -l
gives a list of signals.


Or, if you have an exit in the menu, then you could use:


trap '' 1 2 3

a NULL command, which will just ignore the signals listed.


hth
bv

"The lyf so short, the craft so long to lerne." - Chaucer
Ryan Goh
Frequent Advisor

Re: How to execute command in root as other user account?

You should use sudo package to do the task. Use visudo to edit /etc/sudoers file, The /etc/sudoers file contains all the configuration and permission parameters needed for sudo to work.

For complete information, you can refer to this link,
The /etc/sudoers file contains all the configuration and permission parameters needed for sudo to work



Ryan Goh
Frequent Advisor

Re: How to execute command in root as other user account?

You should use sudo package to do the task. Use visudo to edit /etc/sudoers file, The /etc/sudoers file contains all the configuration and permission parameters needed for sudo to work.

For complete information, you can refer to this link,

http://www.gratisoft.us/sudo/man/sudoers.html