Find out username and UID/GID

Discussion in 'Python' started by Florian Lindner, Jan 4, 2004.

  1. Hello,
    how can I find out the username and it's UID and GID on a linux system,
    using the most recent python version? If possible, without the use of extra
    libraries.
    Thanks,
    Florian
     
    Florian Lindner, Jan 4, 2004
    #1
    1. Advertising

  2. Florian Lindner

    Paul Rubin Guest

    Florian Lindner <> writes:
    > how can I find out the username and it's UID and GID on a linux system,
    > using the most recent python version? If possible, without the use of extra
    > libraries.


    os.getuid(), os.getgid()
     
    Paul Rubin, Jan 4, 2004
    #2
    1. Advertising

  3. Florian Lindner

    Gerrit Holl Guest

    Florian Lindner wrote:
    > how can I find out the username and it's UID and GID on a linux system,
    > using the most recent python version? If possible, without the use of extra
    > libraries.


    >>> import os
    >>> import pwd
    >>> os.getuid()

    500
    >>> os.getgid()

    500
    >>> pwd.getpwuid(500)

    ('gerrit', 'x', 500, 500, 'Gerrit Holl', '/home/gerrit', '/bin/bash')

    I think there is a simpler way for the last one in the docs, but I'm not
    entirely sure.

    yours,
    Gerrit.

    --
    188. If an artizan has undertaken to rear a child and teaches him his
    craft, he can not be demanded back.
    -- 1780 BC, Hammurabi, Code of Law
    --
    Asperger's Syndrome - a personal approach:
    http://people.nl.linux.org/~gerrit/english/
     
    Gerrit Holl, Jan 4, 2004
    #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.
Similar Threads
  1. Florian Lindner

    Get UID of username

    Florian Lindner, Jan 5, 2004, in forum: Python
    Replies:
    2
    Views:
    648
    Hallvard B Furuseth
    Jan 5, 2004
  2. Batista, Facundo

    RE: Get UID of username

    Batista, Facundo, Jan 5, 2004, in forum: Python
    Replies:
    0
    Views:
    430
    Batista, Facundo
    Jan 5, 2004
  3. raocheng
    Replies:
    0
    Views:
    3,796
    raocheng
    Jan 20, 2008
  4. Dave Ardrey

    Messing with UID's and GID's

    Dave Ardrey, Jun 30, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    138
    Greg Bacon
    Jun 30, 2003
  5. hakim

    setting uid gid after fork

    hakim, Aug 28, 2007, in forum: Perl Misc
    Replies:
    1
    Views:
    157
    John W. Krahn
    Aug 28, 2007
Loading...

Share This Page