su-to-root is a simple script to give an interactive front-end to su. It can be used in menu entry commands to ask for the root password.
This is extermly useful when you want to use it from menu based shell script. Most menu entries simply start an editor or a game or whatever. But some menu entries would like to give the user the ability to change important settings in the system, that require root privileges. su-to-root script can be used to ask for the root password.
Examples:
To restart Apache web server you need to type command as follows:
$ su-to-root -c "/etc/init.d/apache-perl restart"
Output:
About to execute /etc/init.d/apache-perl restart. This command needs root privileges to be executed. enter root passwd: Password: Restarting apache-perl 1.3 web server....
If command or password failed it will prompt back user with "Try again? (y/n)" prompt.
$ su-to-root -c "/etc/init.d/apache-perl restart"
Output:
About to execute /etc/init.d/apache-perl restart. This command needs root privileges to be executed. enter root passwd: Password: su: Authentication failure Sorry. Incorrect password or command failed. Try again? (y/n)
This kind of flexibility always needed when you write menubased shell script. If your program/command is a X11 program that do not require a terminal then you need to pass -X option to su-to-root command:
$ su-to-root -c "network-admin"
Where,
- -c COMMAND : The command to execute as a string. This option is mandatory.
- -X : The command is a X11 program that do not require a terminal
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 2 comments… read them below or add one }
How to avoid the password prompt or provide some default value while running su command through shell script on Linux?
The problem I am facing is that the shell script contains the su oracle command which prompts for a password, whereas I don’t want any user interaction once the script is triggered.
To add on, the script is not triggered from root user, otherwise if run from root the password was not required.
Setup sudo to run command as root user so that you can avoid the password prompt:
http://www.cyberciti.biz/tips/allow-a-normal-user-to-run-commands-as-root.html