shell script to auto enter password shell script to auto enter password shell shell

shell script to auto enter password


you may add your ifconfig command for your id in your /etc/sudoers sudo config file


EDIT: I've realized by now that you can't actually do this unless you wrap these commands in a binary. For example, using the system() function from a C program. I guess that setuid shell scripts are such a bad idea that linux doesn't use them at all :).

While it can be dangerous in some circumstances, you can make your script setuid. To do this, put that command into a file like so:

#!/bin/bashifconfig en1 ether 00:11:22:33:44:55

Then set the permissions so that it's owned by root but only you can touch the file:

$sudo chown root file.sh$sudo chgrp username file.sh$sudo chmod 070 file.sh

Then make it suid:

$sudo chmod +s file.sh

Now you should be able to execute this file as your user, but have it run with root privileges.


You don't want to put your root password in an accessible file.

Better would be to make just that command sudoable without password.

Try entering in /etc/sudoers

<your username> ALL=(ALL) NOPASSWD: ifconfig

This says that your user shouldn't need to enter a password for sudo as long as the command is ifconfig.

You should probably read about how the sudoers file works in general first though. Don't know what is you're on, but here's docs for Ubuntu:https://help.ubuntu.com/community/Sudoers

Here are docs for OSX http://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/sudoers.5.html