Results 1 to 7 of 7

Thread: [SOLVED] Script that will write to Sudoers file

  1. #1
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    [SOLVED] Script that will write to Sudoers file

    Hi Everyone,

    To edit the Sudoers file you enter:

    export EDITOR=gedit && sudo visudo

    However, I want to update my script to place some text in this file without actually opening it up.

    I know how to do this with other files, but when I do it to Sudoers it corrupts the file in some way and then you have NO sudo priviliges anymore. Basically, you have to do a re-install.

    Sudoers has 440 permissions and belongs to root.

    I thought to change the permissions and even chmod it from root to user to add text and then put it back. However, that didn't work for me either.

    Does anyone have an idea of how it could be done?

    Thanks in advance for any help ...

  2. #2
    Join Date
    Apr 2007
    Beans
    14,781

    Re: Script that will write to Sudoers file

    # This file MUST be edited with the 'visudo' command as root.
    #
    # See the man page for details on how to write a sudoers file.
    I think they mean it...

  3. #3
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Script that will write to Sudoers file

    Thanks LaRoza...

    Just seems like one of those things where if you have a sudo password, you should be able to at least make it work even if you had to do a run-a-round...

  4. #4
    Join Date
    Apr 2007
    Beans
    14,781

    Re: Script that will write to Sudoers file

    It seems that since sudo is a very important security feature of Ubuntu, it has the utmost security.

  5. #5
    Join Date
    Dec 2004
    Location
    Manchester
    Beans
    2,086
    Distro
    Ubuntu Mate 15.10 Wily Werewolf

    Re: Script that will write to Sudoers file

    visudo is a wrapper that makes a temp version of the sudoers file. nad then runs the command in the EDITOR variable. when that finishes it checks the syntax of the temp file, and only if it is ok, updates the actual sudoers file.

    so if you make a program that takes a file name as an argument, and inserts text into the file given. then you can set EDITOR to the path of you program, and then called visudo.

  6. #6
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,458

    Re: Script that will write to Sudoers file

    Having some other processes writing to sudoers even when they might be sudo sounds like a massive escalation hole waiting to happen. That's why it needs to be done manually by root.
    LambdaGrok. | #ubuntu-programming on FreeNode

  7. #7
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [SOLVED] Script that will write to Sudoers file

    thanks everyone...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •