Search

Finding the user id of a user

Every user in linux is recognized by a unique user id. Here are a few ways you can find out the user id of a user.

1. Login as the user whose user id is to be found out
2. Open a terminal
3. Run the command


The number that will appear as the output is the user id of the currently logged in user.

If you want to know the user id of user with out logging in as that user .

The easiest way is mentioned in the first comment below (updating the blog after receiving the comment )

Another more round about way is to use the script shown below.

uid_script:


Save the script and give execute permissions.
Execute the script



output:



3 comments:

  1. Seriously ?

    Have you ever heard of id ? (/usr/bin/id)

    % id apache
    uid=80(apache) gid=80(apache) groups=80(apache)

    And if you really want to write a script, could you please leave awk alone for such easy tasks ?

    read username
    grep ^$username /etc/passwd | cut -d: -f 3

    ReplyDelete
  2. Just in case :

    % id -u apache
    80

    ReplyDelete