How do I get my python program to get the root password ?

Discussion in 'Python' started by Linuxguy123, Jan 24, 2009.

  1. Linuxguy123

    Linuxguy123 Guest

    I want to make a python program that I can run as a normal user that
    changes the permission on some device files. It will need to ask me for
    the root password and then run chown as root in order to do this.

    How do I accomplish this (easily) ?

    Thanks
    Linuxguy123, Jan 24, 2009
    #1
    1. Advertising

  2. wrote:
    > On 2009-01-24, Linuxguy123 <> wrote:
    >
    >
    >> I want to make a python program that I can run as a normal
    >> user that changes the permission on some device files. It
    >> will need to ask me for the root password and then run chown
    >> as root in order to do this.
    >>
    >> How do I accomplish this (easily) ?
    >>

    >
    > The short answer is: you don't accomplish that easily.
    >
    > The long answer is: you can accomplishity difficultly by using
    > a pty or the pexect module to execute the su or sudo command.
    >
    >


    Check out libsudo. It is a simple library that simply calls sudo
    program except it is does all the work of reading/writing the pipes for
    you. You could then use ctypes to interface to it. Sudo doesn't use
    the root password but the password of the user executing the command,
    but there may be a way to make it use the password of the user the
    command is executed as instead in /etc/sudoers. I don't really know, I
    just have mine set up for my main user account to be able to execute any
    command.


    Brian Vanderburg II
    Brian Allen Vanderburg II, Jan 24, 2009
    #2
    1. Advertising

  3. Linuxguy123

    Aahz Guest

    In article <>,
    Linuxguy123 <> wrote:
    >
    >I want to make a python program that I can run as a normal user that
    >changes the permission on some device files. It will need to ask me for
    >the root password and then run chown as root in order to do this.
    >
    >How do I accomplish this (easily) ?


    The easiest -- really -- is to just make it a root script and run it with
    sudo. If you're on Ubuntu, that's pretty much the only option (without
    resorting to complicated ways of running sudo) -- the standard Ubuntu
    setup doesn't have a root password.
    --
    Aahz () <*> http://www.pythoncraft.com/

    Weinberg's Second Law: If builders built buildings the way programmers wrote
    programs, then the first woodpecker that came along would destroy civilization.
    Aahz, Jan 24, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page