Proper syntax for “id -r” command

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

up vote
5
down vote

favorite

3

I’m trying to see if id -r will print out the UID or username of the user who logged into the system despite any su‘s or sudo‘s. I’m interested in doing this so I can keep people a little more accountable and to tailor script functioning accordingly (i.e: they issue a sudo on a script and it pulls information from the logged in user’s home directory).

I realize sudo sets SUDO_USER but I don’t want to rely on this because it’s a variable that can be modified by the user, and it just has the username of the user who issued the most recent sudo (i.e: sudo -i ; sudo -iu randomUser ; echo $SUDO_USER prints out “root” instead of the actual user).

Nothing in the man pages or that I can find online seems to indicate what the proper use of this command is and the obvious permutations aren’t working:

[root@ditirlns03 ~]# id -r
id: cannot print only names or real IDs in default format
[root@ditirlns03 ~]# id -r jadavis6
id: cannot print only names or real IDs in default format
[root@ditirlns03 ~]# id -r root
id: cannot print only names or real IDs in default format

At this point, I’m still not sure id -r is going to print out what I want, mostly because I can’t figure out how to get it to print out anything at all.

share|improve this question

    up vote
    5
    down vote

    favorite

    3

    I’m trying to see if id -r will print out the UID or username of the user who logged into the system despite any su‘s or sudo‘s. I’m interested in doing this so I can keep people a little more accountable and to tailor script functioning accordingly (i.e: they issue a sudo on a script and it pulls information from the logged in user’s home directory).

    I realize sudo sets SUDO_USER but I don’t want to rely on this because it’s a variable that can be modified by the user, and it just has the username of the user who issued the most recent sudo (i.e: sudo -i ; sudo -iu randomUser ; echo $SUDO_USER prints out “root” instead of the actual user).

    Nothing in the man pages or that I can find online seems to indicate what the proper use of this command is and the obvious permutations aren’t working:

    [root@ditirlns03 ~]# id -r
    id: cannot print only names or real IDs in default format
    [root@ditirlns03 ~]# id -r jadavis6
    id: cannot print only names or real IDs in default format
    [root@ditirlns03 ~]# id -r root
    id: cannot print only names or real IDs in default format
    

    At this point, I’m still not sure id -r is going to print out what I want, mostly because I can’t figure out how to get it to print out anything at all.

    share|improve this question

      up vote
      5
      down vote

      favorite

      3

      up vote
      5
      down vote

      favorite

      3
      3

      I’m trying to see if id -r will print out the UID or username of the user who logged into the system despite any su‘s or sudo‘s. I’m interested in doing this so I can keep people a little more accountable and to tailor script functioning accordingly (i.e: they issue a sudo on a script and it pulls information from the logged in user’s home directory).

      I realize sudo sets SUDO_USER but I don’t want to rely on this because it’s a variable that can be modified by the user, and it just has the username of the user who issued the most recent sudo (i.e: sudo -i ; sudo -iu randomUser ; echo $SUDO_USER prints out “root” instead of the actual user).

      Nothing in the man pages or that I can find online seems to indicate what the proper use of this command is and the obvious permutations aren’t working:

      [root@ditirlns03 ~]# id -r
      id: cannot print only names or real IDs in default format
      [root@ditirlns03 ~]# id -r jadavis6
      id: cannot print only names or real IDs in default format
      [root@ditirlns03 ~]# id -r root
      id: cannot print only names or real IDs in default format
      

      At this point, I’m still not sure id -r is going to print out what I want, mostly because I can’t figure out how to get it to print out anything at all.

      share|improve this question

      I’m trying to see if id -r will print out the UID or username of the user who logged into the system despite any su‘s or sudo‘s. I’m interested in doing this so I can keep people a little more accountable and to tailor script functioning accordingly (i.e: they issue a sudo on a script and it pulls information from the logged in user’s home directory).

      I realize sudo sets SUDO_USER but I don’t want to rely on this because it’s a variable that can be modified by the user, and it just has the username of the user who issued the most recent sudo (i.e: sudo -i ; sudo -iu randomUser ; echo $SUDO_USER prints out “root” instead of the actual user).

      Nothing in the man pages or that I can find online seems to indicate what the proper use of this command is and the obvious permutations aren’t working:

      [root@ditirlns03 ~]# id -r
      id: cannot print only names or real IDs in default format
      [root@ditirlns03 ~]# id -r jadavis6
      id: cannot print only names or real IDs in default format
      [root@ditirlns03 ~]# id -r root
      id: cannot print only names or real IDs in default format
      

      At this point, I’m still not sure id -r is going to print out what I want, mostly because I can’t figure out how to get it to print out anything at all.

      linux command-line coreutils audit uid

      share|improve this question

      share|improve this question

      share|improve this question

      share|improve this question

      edited Nov 29 at 0:56

      imz — Ivan Zakharyaschev

      6,31394091

      6,31394091

      asked May 1 ’13 at 14:18

      Bratchley

      11.8k64388

      11.8k64388

          2 Answers
          2

          active

          oldest

          votes

          up vote
          5
          down vote

          accepted

          -r must be used in conjunction with another option. For example:

          $ id -Gr
          1000 4 24 27 30 46 109 124
          

          Quoting the man page:

          -r, --real
          print the real ID instead of  the  effective  ID,  with -ugG
          

          share|improve this answer

          • Yeah I had tried that but when looking at the output it printed 0 for id -ru so I thought I did something wrong. Do you know of a better way to get the user ID or username as it would appear in audit logs (the auid)?
            – Bratchley
            May 1 ’13 at 15:53

          • 2

            It sounds like you’re interested in getting the owner of the current tty. The following should do the trick for you: stat -c "%U" $(tty). But that’s really a different question. If you started another question it’d be easier to find.
            – Frederik Deweerdt
            May 1 ’13 at 17:17

          up vote
          0
          down vote

          The program and the docs deviate from standard practices:

          If -ugG actually means -u|g|G[modifier] (which apparently it does), then it should be documented that way. The authors didn’t seem to think it was worth the effort. However, when the user does the same thing (as Mr. Davis quite reasonably tried):

          -ru, a legitimate, intuitive assumption, returns an error.

          Apropos this tip:

          stat -c "%U" $(tty)
          

          Probably would have helped to mention that it’s shell-specific.

          share|improve this answer

            Your Answer

            StackExchange.ready(function() {
            var channelOptions = {
            tags: “”.split(” “),
            id: “106”
            };
            initTagRenderer(“”.split(” “), “”.split(” “), channelOptions);

            StackExchange.using(“externalEditor”, function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using(“snippets”, function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: ‘answer’,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: “”,
            imageUploader: {
            brandingHtml: “Powered by u003ca class=”icon-imgur-white” href=”https://imgur.com/”u003eu003c/au003e”,
            contentPolicyHtml: “User contributions licensed under u003ca href=”https://creativecommons.org/licenses/by-sa/3.0/”u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href=”https://stackoverflow.com/legal/content-policy”u003e(content policy)u003c/au003e”,
            allowUrls: true
            },
            onDemand: true,
            discardSelector: “.discard-answer”
            ,immediatelyShowMarkdownHelp:true
            });

            }
            });

            draft saved
            draft discarded

            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin(‘.new-post-login’, ‘https%3a%2f%2funix.stackexchange.com%2fquestions%2f74307%2fproper-syntax-for-id-r-command%23new-answer’, ‘question_page’);
            }
            );

            Post as a guest

            Required, but never shown

            2 Answers
            2

            active

            oldest

            votes

            2 Answers
            2

            active

            oldest

            votes

            active

            oldest

            votes

            active

            oldest

            votes

            up vote
            5
            down vote

            accepted

            -r must be used in conjunction with another option. For example:

            $ id -Gr
            1000 4 24 27 30 46 109 124
            

            Quoting the man page:

            -r, --real
            print the real ID instead of  the  effective  ID,  with -ugG
            

            share|improve this answer

            • Yeah I had tried that but when looking at the output it printed 0 for id -ru so I thought I did something wrong. Do you know of a better way to get the user ID or username as it would appear in audit logs (the auid)?
              – Bratchley
              May 1 ’13 at 15:53

            • 2

              It sounds like you’re interested in getting the owner of the current tty. The following should do the trick for you: stat -c "%U" $(tty). But that’s really a different question. If you started another question it’d be easier to find.
              – Frederik Deweerdt
              May 1 ’13 at 17:17

            up vote
            5
            down vote

            accepted

            -r must be used in conjunction with another option. For example:

            $ id -Gr
            1000 4 24 27 30 46 109 124
            

            Quoting the man page:

            -r, --real
            print the real ID instead of  the  effective  ID,  with -ugG
            

            share|improve this answer

            • Yeah I had tried that but when looking at the output it printed 0 for id -ru so I thought I did something wrong. Do you know of a better way to get the user ID or username as it would appear in audit logs (the auid)?
              – Bratchley
              May 1 ’13 at 15:53

            • 2

              It sounds like you’re interested in getting the owner of the current tty. The following should do the trick for you: stat -c "%U" $(tty). But that’s really a different question. If you started another question it’d be easier to find.
              – Frederik Deweerdt
              May 1 ’13 at 17:17

            up vote
            5
            down vote

            accepted

            up vote
            5
            down vote

            accepted

            -r must be used in conjunction with another option. For example:

            $ id -Gr
            1000 4 24 27 30 46 109 124
            

            Quoting the man page:

            -r, --real
            print the real ID instead of  the  effective  ID,  with -ugG
            

            share|improve this answer

            -r must be used in conjunction with another option. For example:

            $ id -Gr
            1000 4 24 27 30 46 109 124
            

            Quoting the man page:

            -r, --real
            print the real ID instead of  the  effective  ID,  with -ugG
            

            share|improve this answer

            share|improve this answer

            share|improve this answer

            answered May 1 ’13 at 15:39

            Frederik Deweerdt

            2,9821116

            2,9821116

            • Yeah I had tried that but when looking at the output it printed 0 for id -ru so I thought I did something wrong. Do you know of a better way to get the user ID or username as it would appear in audit logs (the auid)?
              – Bratchley
              May 1 ’13 at 15:53

            • 2

              It sounds like you’re interested in getting the owner of the current tty. The following should do the trick for you: stat -c "%U" $(tty). But that’s really a different question. If you started another question it’d be easier to find.
              – Frederik Deweerdt
              May 1 ’13 at 17:17

            • Yeah I had tried that but when looking at the output it printed 0 for id -ru so I thought I did something wrong. Do you know of a better way to get the user ID or username as it would appear in audit logs (the auid)?
              – Bratchley
              May 1 ’13 at 15:53

            • 2

              It sounds like you’re interested in getting the owner of the current tty. The following should do the trick for you: stat -c "%U" $(tty). But that’s really a different question. If you started another question it’d be easier to find.
              – Frederik Deweerdt
              May 1 ’13 at 17:17

            Yeah I had tried that but when looking at the output it printed 0 for id -ru so I thought I did something wrong. Do you know of a better way to get the user ID or username as it would appear in audit logs (the auid)?
            – Bratchley
            May 1 ’13 at 15:53

            Yeah I had tried that but when looking at the output it printed 0 for id -ru so I thought I did something wrong. Do you know of a better way to get the user ID or username as it would appear in audit logs (the auid)?
            – Bratchley
            May 1 ’13 at 15:53

            2

            2

            It sounds like you’re interested in getting the owner of the current tty. The following should do the trick for you: stat -c "%U" $(tty). But that’s really a different question. If you started another question it’d be easier to find.
            – Frederik Deweerdt
            May 1 ’13 at 17:17

            It sounds like you’re interested in getting the owner of the current tty. The following should do the trick for you: stat -c "%U" $(tty). But that’s really a different question. If you started another question it’d be easier to find.
            – Frederik Deweerdt
            May 1 ’13 at 17:17

            up vote
            0
            down vote

            The program and the docs deviate from standard practices:

            If -ugG actually means -u|g|G[modifier] (which apparently it does), then it should be documented that way. The authors didn’t seem to think it was worth the effort. However, when the user does the same thing (as Mr. Davis quite reasonably tried):

            -ru, a legitimate, intuitive assumption, returns an error.

            Apropos this tip:

            stat -c "%U" $(tty)
            

            Probably would have helped to mention that it’s shell-specific.

            share|improve this answer

              up vote
              0
              down vote

              The program and the docs deviate from standard practices:

              If -ugG actually means -u|g|G[modifier] (which apparently it does), then it should be documented that way. The authors didn’t seem to think it was worth the effort. However, when the user does the same thing (as Mr. Davis quite reasonably tried):

              -ru, a legitimate, intuitive assumption, returns an error.

              Apropos this tip:

              stat -c "%U" $(tty)
              

              Probably would have helped to mention that it’s shell-specific.

              share|improve this answer

                up vote
                0
                down vote

                up vote
                0
                down vote

                The program and the docs deviate from standard practices:

                If -ugG actually means -u|g|G[modifier] (which apparently it does), then it should be documented that way. The authors didn’t seem to think it was worth the effort. However, when the user does the same thing (as Mr. Davis quite reasonably tried):

                -ru, a legitimate, intuitive assumption, returns an error.

                Apropos this tip:

                stat -c "%U" $(tty)
                

                Probably would have helped to mention that it’s shell-specific.

                share|improve this answer

                The program and the docs deviate from standard practices:

                If -ugG actually means -u|g|G[modifier] (which apparently it does), then it should be documented that way. The authors didn’t seem to think it was worth the effort. However, when the user does the same thing (as Mr. Davis quite reasonably tried):

                -ru, a legitimate, intuitive assumption, returns an error.

                Apropos this tip:

                stat -c "%U" $(tty)
                

                Probably would have helped to mention that it’s shell-specific.

                share|improve this answer

                share|improve this answer

                share|improve this answer

                edited Jul 21 ’14 at 17:55

                HalosGhost

                3,68592235

                3,68592235

                answered Jul 21 ’14 at 17:42

                randy james

                1

                1

                    draft saved
                    draft discarded

                    Thanks for contributing an answer to Unix & Linux Stack Exchange!

                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid

                    • Asking for help, clarification, or responding to other answers.
                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.

                    Some of your past answers have not been well-received, and you’re in danger of being blocked from answering.

                    Please pay close attention to the following guidance:

                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid

                    • Asking for help, clarification, or responding to other answers.
                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.

                    draft saved

                    draft discarded

                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin(‘.new-post-login’, ‘https%3a%2f%2funix.stackexchange.com%2fquestions%2f74307%2fproper-syntax-for-id-r-command%23new-answer’, ‘question_page’);
                    }
                    );

                    Post as a guest

                    Required, but never shown

                    Required, but never shown

                    Required, but never shown

                    Required, but never shown

                    Required, but never shown

                    Required, but never shown

                    Required, but never shown

                    Required, but never shown

                    Required, but never shown

                    Related Post

                    Leave a Reply

                    Your email address will not be published. Required fields are marked *