ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Why does a command work after sudo su, but not with sudo?

    Scheduled Pinned Locked Moved IT Discussion
    13 Posts 7 Posters 923 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • black3dynamiteB
      black3dynamite
      last edited by

      It works for me.

      1 Reply Last reply Reply Quote 0
      • matteo nunziatiM
        matteo nunziati @Kelly
        last edited by

        @kelly sudo su lets you load part of the root env if I remember correctly.
        Basically sudo lets your user do privileged work.
        Sudo su lets your user become root. And then ezecute code as root.
        This not the same as logging as root but some of the env should be loaded.

        KellyK 1 Reply Last reply Reply Quote 1
        • dbeatoD
          dbeato
          last edited by

          Sometimes for me has been the environmental variables (like for zimbra) or like root when you cannot sudo cd to a directory.

          1 Reply Last reply Reply Quote 0
          • KellyK
            Kelly @matteo nunziati
            last edited by

            @matteo-nunziati said in Why does a command work after sudo su, but not with sudo?:

            @kelly sudo su lets you load part of the root env if I remember correctly.
            Basically sudo lets your user do privileged work.
            Sudo su lets your user become root. And then ezecute code as root.
            This not the same as logging as root but some of the env should be loaded.

            Is the default account that is created when you set up Ubuntu not root?

            JaredBuschJ 1 Reply Last reply Reply Quote 1
            • KellyK
              Kelly
              last edited by

              Sorry for the lack of follow up yesterday. I was at a client site.

              1 Reply Last reply Reply Quote 1
              • JaredBuschJ
                JaredBusch @Kelly
                last edited by

                @kelly said in Why does a command work after sudo su, but not with sudo?:

                @matteo-nunziati said in Why does a command work after sudo su, but not with sudo?:

                @kelly sudo su lets you load part of the root env if I remember correctly.
                Basically sudo lets your user do privileged work.
                Sudo su lets your user become root. And then ezecute code as root.
                This not the same as logging as root but some of the env should be loaded.

                Is the default account that is created when you set up Ubuntu not root?

                A root account exists by default, but you you don't populate the root password, it makes a user account with sudo privileges.

                If you give the root account a password during setup, you can create a user account without sudo I do believe.

                Is that what you are asking?

                KellyK 1 Reply Last reply Reply Quote 0
                • KellyK
                  Kelly @JaredBusch
                  last edited by Kelly

                  @jaredbusch said in Why does a command work after sudo su, but not with sudo?:

                  @kelly said in Why does a command work after sudo su, but not with sudo?:

                  @matteo-nunziati said in Why does a command work after sudo su, but not with sudo?:

                  @kelly sudo su lets you load part of the root env if I remember correctly.
                  Basically sudo lets your user do privileged work.
                  Sudo su lets your user become root. And then ezecute code as root.
                  This not the same as logging as root but some of the env should be loaded.

                  Is the default account that is created when you set up Ubuntu not root?

                  A root account exists by default, but you you don't populate the root password, it makes a user account with sudo privileges.

                  If you give the root account a password during setup, you can create a user account without sudo I do believe.

                  Is that what you are asking?

                  Yes, that answers my question. Just to summarize how I am understanding it from what has been said:

                  • I was logged in with a sudoer, but not root

                  • When I do sudo su I am actually switching to root

                  • Since this is the case the user context was different and my sudoer user account did not have permissions to the file, but in the root user context I would have permissions and thus the command succeeded.

                  Is that all correct?

                  JaredBuschJ 1 Reply Last reply Reply Quote 0
                  • JaredBuschJ
                    JaredBusch @Kelly
                    last edited by JaredBusch

                    @kelly said in Why does a command work after sudo su, but not with sudo?:

                    @jaredbusch said in Why does a command work after sudo su, but not with sudo?:

                    @kelly said in Why does a command work after sudo su, but not with sudo?:

                    @matteo-nunziati said in Why does a command work after sudo su, but not with sudo?:

                    @kelly sudo su lets you load part of the root env if I remember correctly.
                    Basically sudo lets your user do privileged work.
                    Sudo su lets your user become root. And then ezecute code as root.
                    This not the same as logging as root but some of the env should be loaded.

                    Is the default account that is created when you set up Ubuntu not root?

                    A root account exists by default, but you you don't populate the root password, it makes a user account with sudo privileges.

                    If you give the root account a password during setup, you can create a user account without sudo I do believe.

                    Is that what you are asking?

                    Yes, that answers my question. Just to summarize how I am understanding it from what has been said:

                    • I was logged in with a sudoer, but not root

                    • When I do sudo su I am actually switching to root

                    • Since this is the case the user context was different and my sudoer user account did not have permissions to the file, but in the root user context I would have permissions and thus the command succeeded.

                    Is that all correct?

                    Generally yes. It is unusual not to have access to something with sudo so more very specific things would need determined.

                    Example, this file is owned by root.

                    [jbusch@nginxproxy ~]$ ls -l /etc/nginx/conf.d/jaredbusch.com.conf 
                    -rw-r--r--. 1 root root 1108 Sep  5  2017 /etc/nginx/conf.d/jaredbusch.com.conf
                    

                    If I do this

                    [jbusch@nginxproxy ~]$ nano /etc/nginx/conf.d/jaredbusch.com.conf 
                    

                    I get this.
                    0_1528226957838_6b8a689c-9cb0-4c82-8bc8-eb4c0e9e4af3-image.png

                    But

                    [jbusch@nginxproxy ~]$ sudo nano /etc/nginx/conf.d/jaredbusch.com.conf 
                    [sudo] password for jbusch: 
                    

                    I get this. (ie writable)
                    0_1528227025071_045a1b8c-db86-43dd-8cd7-d4a7a0cc327c-image.png

                    This example is on CentOS 7. I do not have handy access to an Ubuntu system. I guess I could check with a Debian system.

                    dbeatoD 1 Reply Last reply Reply Quote 4
                    • dbeatoD
                      dbeato @JaredBusch
                      last edited by

                      @jaredbusch said in Why does a command work after sudo su, but not with sudo?:

                      @kelly said in Why does a command work after sudo su, but not with sudo?:

                      @jaredbusch said in Why does a command work after sudo su, but not with sudo?:

                      @kelly said in Why does a command work after sudo su, but not with sudo?:

                      @matteo-nunziati said in Why does a command work after sudo su, but not with sudo?:

                      @kelly sudo su lets you load part of the root env if I remember correctly.
                      Basically sudo lets your user do privileged work.
                      Sudo su lets your user become root. And then ezecute code as root.
                      This not the same as logging as root but some of the env should be loaded.

                      Is the default account that is created when you set up Ubuntu not root?

                      A root account exists by default, but you you don't populate the root password, it makes a user account with sudo privileges.

                      If you give the root account a password during setup, you can create a user account without sudo I do believe.

                      Is that what you are asking?

                      Yes, that answers my question. Just to summarize how I am understanding it from what has been said:

                      • I was logged in with a sudoer, but not root

                      • When I do sudo su I am actually switching to root

                      • Since this is the case the user context was different and my sudoer user account did not have permissions to the file, but in the root user context I would have permissions and thus the command succeeded.

                      Is that all correct?

                      Generally yes. It is unusual not to have access to something with sudo so more very specific things would need determined.

                      Example, this file is owned by root.

                      [jbusch@nginxproxy ~]$ ls -l /etc/nginx/conf.d/jaredbusch.com.conf 
                      -rw-r--r--. 1 root root 1108 Sep  5  2017 /etc/nginx/conf.d/jaredbusch.com.conf
                      

                      If I do this

                      [jbusch@nginxproxy ~]$ nano /etc/nginx/conf.d/jaredbusch.com.conf 
                      

                      I get this.
                      0_1528226957838_6b8a689c-9cb0-4c82-8bc8-eb4c0e9e4af3-image.png

                      But

                      [jbusch@nginxproxy ~]$ sudo nano /etc/nginx/conf.d/jaredbusch.com.conf 
                      [sudo] password for jbusch: 
                      

                      I get this. (ie writable)
                      0_1528227025071_045a1b8c-db86-43dd-8cd7-d4a7a0cc327c-image.png

                      This example is on CentOS 7. I do not have handy access to an Ubuntu system. I guess I could check with a Debian system.

                      Same things happens in Ubuntu/Debian

                      1 Reply Last reply Reply Quote 2
                      • KellyK
                        Kelly
                        last edited by

                        Thanks. I appreciate the schooling.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post