know user id group - Unix

This is a discussion on know user id group - Unix ; Hi, Can someone guide me how to determine which gruop the user id belongs to. Thanks, Prateek...

+ Reply to Thread
Results 1 to 5 of 5

Thread: know user id group

  1. know user id group

    Hi,
    Can someone guide me how to determine which gruop the user id belongs
    to.
    Thanks,
    Prateek


  2. Re: know user id group

    * Prateek [2007.05.01 13:38]:
    > Can someone guide me how to determine which gruop the user
    > id belongs to.


    groups $( awk -F: '$3 == userid { print $1 }' /etc/passwd )

    It's easier with the user name:

    groups username

    --
    JR

  3. Re: know user id group

    On 1 May 2007 06:38:09 -0700, Prateek wrote:
    > Hi,
    > Can someone guide me how to determine which gruop the user id belongs
    > to.



    grep prateek /etc/passwd
    prateek:x:1510:1517rateek name here:/home/prateek:/bin/bash
    ^ ^
    | |
    User id----' `----- group id (primary)

    To return all groups prateek might share:
    grep prateek /etc/groups


  4. Re: know user id group

    2007-05-1, 06:38(-07), Prateek:
    > Hi,
    > Can someone guide me how to determine which gruop the user id belongs

    [...]

    Note that the system (unix kernel) only knows of the uid, euid,
    gid, egid and a list of supplementary gids of a *process*, not
    a user.

    When you log in using your user *name* (not id), the login
    application (can be login, or xdm, kdm, dtsession...) looks up
    your user name into a database.

    That database can consist in the /etc/passwd and /etc/group
    files or in a NIS/NIS+/hesiod/LDAP/SQL... database of user and
    groups.

    The login application sets the uid, gid, egid, euid, and
    supplementary gids of the process from which will descend all
    the other processes in your login session (for instance the
    process that will execute your login shell when logging in a
    terminal) based on the information stored in that database.

    For instance, when using /etc/passwd, /etc/group, the username
    will be looked up in /etc/passwd and uid,euid,gid,egid set
    according to the 3rd and 4th fields. Then /etc/group will also
    be processed to determine the list of supplementary gids.

    There can be different user names for a given user id, with
    different lists of groups or gids, and changing the content of
    the database will not have any effect on processes that are
    already running.

    So, generally, there's no correspondance between uid and group
    or list of groups. There is only a correspondance with user name
    and that is only valid at a given point in time.

    If you're interested in knowing the gid, egid and supplementary
    gids of the current process, you can use the getgid, getegid an
    getgroups system calls.

    --
    Stéphane

  5. Re: know user id group

    On 2007-05-01, Prateek wrote:
    > Hi,
    > Can someone guide me how to determine which gruop the user id belongs
    > to.


    Use the 'id' command.

    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

+ Reply to Thread