Decentralise Linux security with Sudo

Although some of us administrators may hesitate to admit it, it is often necessary to relinquish some control and delegate responsibility, especially in multiadministrator environments. Fortunately, you can easily delegate administrative duties on your Linux systems without giving out the root password. Just use Sudo.

The concept behind Sudo (derived from "superuser do") is quite genius in its simplicity: Allow specified users or groups to run root-level commands based on a central configuration file. Sudo also provides verbose logging of all commands and arguments so you can track its usage, which is extremely helpful in tracking problems created by misconfigurations and input error.

If you have ever administered a server on which multiple users need root access, you will immediately see the benefits of Sudo. Here's a look at how you can take advantage of it.

Installing and configuring Sudo

You can obtain Sudo from a variety of locations, but you'll find the latest version here, as well as links to current source packages and different binaries. Some Linux distributions come with Sudo preinstalled or at least have it available as part of their installation CDs.

After you have installed Sudo on your system(s), you will need to modify the configuration file to meet your needs. This file, usually /etc/sudoers, is a plain text file that allows an administrator to outline which users may access which programs and files. You'll also be able to create groups to which certain users and commands can be assigned, making administration that much easier.

The documentation for Sudo advises the use of visudo, an editing program provided with the package, to modify the /etc/sudoers file. Fortunately, visudo not only locks /etc/sudoers to prevent simultaneous modifications but will also check your syntax for any errors. Of course, you may just prefer to use your favourite text editor to set up the sudoers file manually.

Before beginning to configure Sudo, it is a good idea to map out what servers, programs, and commands specific users will need to have access to. For example, what commands relating to the administration of Sendmail, BIND, or Apache can be delegated to other groups? Perhaps you do not want them restarting the daemon, but maybe they can be allowed to add new users or domains. Listing 1 shows an example sudoers file.

Parameters in the sudoers file In the listing, you can see how groups of systems, users, and commands are created with the Host_Alias, User_Alias, and Cmnd_Alias parameters. Let's start with the Host_Alias entry. As long as the /etc/sudoers file can be accessed from each server, multiple hosts can share the same file. In our example, we have created three aliases for our servers and entered one per line. The server names ns1, ns2, mail1, mail2, mail3, and web1 are the local host names for each machine. When a user executes sudo from the command line on one of these servers, Sudo will check the local hostname and provide access based on what it finds. This allows for host-based access, which is helpful since commands often vary depending on the server's role.

The User_Alias command allows us to classify system users and/or groups into a single variable. This variable is then used to grant privileges. There are two aliases in this example, NOC and CALLCENTER. NOC consists of two system accounts: steve and mike, and one system group: noc. Notice the % sign, which tells Sudo to interpret the word that follows as a local group. You will need to create these groups and add users before using them in the sudoers file.

You use the Cmnd_Alias parameter to commands. As you can see, there are five groups of commands: READLOG, USERMOD, RESTART, MODIFY, and ROOTMOD. Since different groups will require different kinds of access, you can break commands into easy-to-manage blocks. You enter commands as follows:

/path/program argument(s)

Sudo will continue to the next line if ", " is encountered. Command aliases can be valuable in this regard, since not every group will need every command available to Sudo.

TechRepublic is the online community and information resource for all IT professionals, from support staff to executives. We offer in-depth technical articles written for IT professionals by IT professionals. In addition to articles on everything from Windows to e-mail to fire walls, we offer IT industry analysis, downloads, management tips, discussion forums, and e-newsletters.

©2001 TechRepublic, Inc.

Advertisement

Talkback 4 comments

    With the /etc/sudoers file tha ...Anonymous -- 19/02/02

    With the /etc/sudoers file that you provided, people would be better advised to give root password out to everyone, perhaps by means of a yellow Post-it attached to the monitor. Then there wouldn't be a sense of false security.

    Both less and vi can switch the files being operated on. Both have shell escapes. That would be a shell with root privileges.

    "cat" is a better option for letting people look at logs. "sudo cat file | more" will do the trick without providing unlimited access.

    If someone has root powers in vi, they have control of the whole system. At that point, sudo becomes a nice logging system, unless they launcha nother shell to hide the commands that they want to use.

    It is also advisable to have a SHELLS alias in the sudoers file so that you can explicitly exclude any shell access to your subcontracted admins. As in "!SHELLS"

    The "userdel root" command ought to prove real interesting to see if one can recover without reloading the OS.

    WARNING many pitfalls for new ...Matt van Amsterdam -- 19/02/02

    WARNING many pitfalls for new sudo user

    I agree with the previous commentator.
    The example sudoers file given here
    has many problems.
    Unfortunately sudo, for most people,
    should be considered a convenience thing
    not a security thing.

    You generally need to do a lot of work
    making it secure. It's a pity more warnings
    and examples are not distributed with sudo
    itself.

    Announcement Welcome Dear Read ...Theo Mueller -- 28/12/02

    Announcement
    Welcome Dear Reader,

    My name is Theo Mueller.
    I would like to inform you personally about my latest book
    " YOU ARE THE WINNER ".
    In this book it is clearly highlighted in a most simple but effective manner how mankind can improve.
    Maybe we may call it " Ego - Mind - Healer or just vice versa".
    It is proven that this book is really valuable for all of us.
    Below advertisement could be printed out and used for the information of your customers or friends.
    This book is highly recommended for all young people to start life most successfully.
    Best Seller

    This message will change the world !

    The latest book "You are the Winner” ISBN 0 - 595 - 23154 - 3 is published by iUniverse in Lincoln NE USA. The author is Theo Mueller.

    The author is trying to reach the world with a wonderful message.

    This book is a jewel for every one! Heeding its message will transform YOU to "A most respected person of our Society"!

    http://www.iuniverse.com/bookstore/book_detail.asp?isbn=0-595-23154-3

    This book is a CONFLICT - SOLVING THRILLER with impressive graphics, which will help to shape the nation towards a better society.
    The subject is about the thinking pattern of human beings and how to control this process.
    This Author writes about self-improvement and motivation as well as environmental issues in a very exciting and easy understanding style.
    This book is valuable for schools and youngsters above 16 years of age but is not less interesting for adults. Its easy reading makes it a good exercise for language schools too, allowing the students to benefit in two subjects at the same time.
    The book will be valuable for school libraries and is advisable as additional reading in social and humanity teachings as well as in motivation programs.
    For a prison library this book will fit in best.
    A good number of clean jokes in-between the texts makes reading some more fun.
    18 true short stories are forming the second half of the book, proving that ALL problems can be solved by dialogue.
    Eleven songs composed and written by the author himself with meaningful lyrics ( written for keyboard ) form the end of the book.
    The book is also available as an e - book version
    (in MS reader ISBN 0-595-73604-1)
    (in Adobe reader ISBN 0-595-73605-X)
    to directly download it into your computer.

    Your buy supports CHARITY.

    Contribution is made to an old folks home for the poor.

    Below is the address to see via internet what the book looks alike. Just click on the URL below and you can page through the whole book.

    http://www.iuniverse.com/bookstore/book_detail.asp?isbn=0-595-23154-3

    For direct contact, as a wholesaler please contact custservice@iuniverse.com

    You may purchase directly via above channel, or order the book in your nearest book shop.
    The book is reviewed and therefore also sold by Ingram Book Group and Baker & Taylor, and with R.R. Bowker's Books.
    You can also find this book in the largest Book shops of http://www.Amazon.com and Barnes&Noble http://www.bn.com and other big book sellers.

    I thank you very much indeed for your kind consideration.

    Thank you so much. Yours caring
    Review committee on behalf of the Author.

    If you have friends who are interested in this literature please help and send them this note.
    Thank you so much.

    Theo Mueller

    If this mail caused inconvenience to you we honestly apologize. This is a one-time message only.

    Honestly a great writer Kurdi Fisher -- 18/05/08 (in reply to #120019106)

    This is the ever best literature I got in my hands.
    It is so true and written in a plane simple manner. A great compliment, if only all people would follow Theo's advice!

Add your opinion

Latest Videos

Sponsored content

Power Centre - Content from our premier sponsors

Blogs

  • Suzanne Tindal Love me, tender
    Considering how expensive and drawn-out tender processes can be to solve problems that might be very immediate, it's little wonder that the Victorian Police IT department tried to work the tender exemptions system.
  • Array 2009 funding drought rolls on
    For Australian start-ups looking for venture capital, 2009 was a very bad year. 2010 may be no better.
  • Array Can not-so-smart meters help the NBN?
    It was interesting to witness Conroy's recent enthusiasm to spruik the NBN's role in supporting the Smart Grid, Smart City initiative. What a pity that Conroy hadn't yet seen the damning report from the Victorian auditor-general about that state's smart-meter roll-out.
  • More blogs »

Tags

Back to top

Featured