Sudify

Sudify is a very simple shell wrapper script to make using sudo less annoying by hiding it. Sudify does this by removing sudo from the command you are running. More specifically, the command you are running is a sym-link to the sudify script, which passes the command you ran, including all arguments, to sudo.

For sudify to work you must have the sudified command(s) you want to run be found in your path before the commands they are sudifying. This can simply be done by putting the directory at the start of your path. I personally keep sudified commands (along with a lot of other commands) in a bin directory in my home directory and have ~/bin appear first in my path.

The sym-links allow the sudify script to be called by multiple different names, without taking up additional space on the file system. Thus the sudified command calls the sudify script which extracts the name of the command you ran and passes it to sudo, including all command line arguments.

#[gtaylor@alpha:~/bin]$ ls -l sudify service chkconfig
lrwxrwxrwx. 1 gtaylor gtaylor   6 Feb  6 21:11 chkconfig -> sudify
lrwxrwxrwx. 1 gtaylor gtaylor   6 Feb  6 21:11 service -> sudify
-rwxrwxr-x. 1 gtaylor gtaylor 405 Feb  6 21:10 sudify
#[gtaylor@alpha:~/bin]$ 

Here we can see I've sudified the chkconfig and service command. So, with ~/bin first in my path, any time I run either of the chkconfig or service commands, I'm indirectly calling sudify, which passes the chkconfig or service command to sudo for me.

If you recall from my Embracing sudo article, I was previously using shell aliases for this function. However, as I stated there, aliases don't work in scripts or as ssh remote commands. Thankfully, sudify and sudified commands do work in scripts and as ssh remote commands. This way I can quite literally run the exact same command (i.e.: yum update) in all three of the following contexts:

sudify

See also:
Sudo, a love hate relationship
Embracing sudo
Command Aliases