4

I'm using Ubuntu 12.04 LTS, and I'm trying to make it so that the specific command

dhclient

doesn't require root privileges. I've done some research that leads me to believe I could unlock an "su" user, which wouldn't require root for anything, but am afraid I'll break something that way.

Maybe I'm asking the two separate questions:

  1. Where do all of the commands that do not require root privileges reside in my OS?

  2. Can I move this command there?

Any way will work in my case, and I'm not even sure if that's how the regular user's commands are distinguished from the rest, to be honest.

2 Answers 2

8

The best way to do this is with sudo, which is very configurable with regard to which user can execute which commands. Use visudo to edit /etc/sudoers (never edit this file directly -- if you make a mistake you will completely lock yourself out). The following entry would allow the user bob to run dhclient without requiring a password.

bob ALL = (root) NOPASSWD: /sbin/dhclient

Bob would run sudo dhclient when in order to execute it.

1
  • It won't let me use "visudo," so i'm going to edit it carefully. EDIT: it has to edited with visudo
    – rofls
    Jun 1, 2012 at 6:44
2

If a specific user can or cannot successfully execute a program (binary or script) depends on two things:

  • The user need execution privileges on the file.

    This isn't a problem: ls -l reveals that any user can execute /sbin/dhclient.

  • The user needs reading, writing and/or execution privileges to the files the program accesses.

    This part is much, much trickier and more dangerous, as it may involve changing the permissions of many files.

For more information, see Chmod - Wikipedia.

The normal way to execute a command with root privileges is sudo. From the manpage:

sudo allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file. The real and effective uid and gid are set to match those of the target user as specified in the passwd file and the group vector is initialized based on the group file (unless the -P option was specified). If the invoking user is root or if the target user is the same as the invoking user, no password is required. Otherwise, sudo requires that users authenticate themselves with a password by default ( NOTE: in the default configuration this is the user's password, not the root password). Once a user has been authenticated, a time stamp is updated and the user may then use sudo without a password for a short period of time (5 minutes unless overridden in sudoers).

The basic syntax in your specific case is:

sudo dhclient

Regarding your other questions:

1.​ Where do all of the commands that do not require root privileges reside in my OS?

Most binaries for all users reside inside /bin, /usr/bin and /usr/local/bin.

Most system binaries (require root privileges) reside in /sbin.

This is just a rule of thumb. You can place binaries everywhere you want.

See also: Filesystem Hierarchy Standard

2.​ Can I move this command there?

Apart from potentially breaking something, this would have absolutely no effect.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .