Why is there a different result when running as user1 and su - user1 -c “command”?

Multi tool use
Multi tool use

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











up vote
0
down vote

favorite












When running as user1 in the same directory (/home/user1/WWW)



[user1@server1 WWW (master)]# touch c


Creates the file c inside the directory.



[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"


gives the error




touch: cannot touch `c': Permission denied




Why can this be?










share|improve this question





















  • @Kusalananda yes the directory is owned by user1:apache. I would suspect the first case would also fail when that was not true.
    – Thomas Moors
    Aug 15 at 13:16






  • 3




    If your remove the - from the command and do su user1 -c ...? With - you do a full login, and may end up in another directory than the directory you're currently in.
    – Kusalananda
    Aug 15 at 13:21










  • @steeldriver That's what I thought. But why would user1 not be able to touch c in their home directory. Is there already a file owned by another user there?
    – Kusalananda
    Aug 15 at 13:22










  • @steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google: su - user1 -c changed the current working directory!
    – Thomas Moors
    Aug 15 at 13:25










  • ... and that file in user1's home directory is owned by another user?
    – Kusalananda
    Aug 15 at 13:26














up vote
0
down vote

favorite












When running as user1 in the same directory (/home/user1/WWW)



[user1@server1 WWW (master)]# touch c


Creates the file c inside the directory.



[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"


gives the error




touch: cannot touch `c': Permission denied




Why can this be?










share|improve this question





















  • @Kusalananda yes the directory is owned by user1:apache. I would suspect the first case would also fail when that was not true.
    – Thomas Moors
    Aug 15 at 13:16






  • 3




    If your remove the - from the command and do su user1 -c ...? With - you do a full login, and may end up in another directory than the directory you're currently in.
    – Kusalananda
    Aug 15 at 13:21










  • @steeldriver That's what I thought. But why would user1 not be able to touch c in their home directory. Is there already a file owned by another user there?
    – Kusalananda
    Aug 15 at 13:22










  • @steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google: su - user1 -c changed the current working directory!
    – Thomas Moors
    Aug 15 at 13:25










  • ... and that file in user1's home directory is owned by another user?
    – Kusalananda
    Aug 15 at 13:26












up vote
0
down vote

favorite









up vote
0
down vote

favorite











When running as user1 in the same directory (/home/user1/WWW)



[user1@server1 WWW (master)]# touch c


Creates the file c inside the directory.



[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"


gives the error




touch: cannot touch `c': Permission denied




Why can this be?










share|improve this question













When running as user1 in the same directory (/home/user1/WWW)



[user1@server1 WWW (master)]# touch c


Creates the file c inside the directory.



[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"


gives the error




touch: cannot touch `c': Permission denied




Why can this be?







sudo group su






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 15 at 13:13









Thomas Moors

12410




12410











  • @Kusalananda yes the directory is owned by user1:apache. I would suspect the first case would also fail when that was not true.
    – Thomas Moors
    Aug 15 at 13:16






  • 3




    If your remove the - from the command and do su user1 -c ...? With - you do a full login, and may end up in another directory than the directory you're currently in.
    – Kusalananda
    Aug 15 at 13:21










  • @steeldriver That's what I thought. But why would user1 not be able to touch c in their home directory. Is there already a file owned by another user there?
    – Kusalananda
    Aug 15 at 13:22










  • @steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google: su - user1 -c changed the current working directory!
    – Thomas Moors
    Aug 15 at 13:25










  • ... and that file in user1's home directory is owned by another user?
    – Kusalananda
    Aug 15 at 13:26
















  • @Kusalananda yes the directory is owned by user1:apache. I would suspect the first case would also fail when that was not true.
    – Thomas Moors
    Aug 15 at 13:16






  • 3




    If your remove the - from the command and do su user1 -c ...? With - you do a full login, and may end up in another directory than the directory you're currently in.
    – Kusalananda
    Aug 15 at 13:21










  • @steeldriver That's what I thought. But why would user1 not be able to touch c in their home directory. Is there already a file owned by another user there?
    – Kusalananda
    Aug 15 at 13:22










  • @steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google: su - user1 -c changed the current working directory!
    – Thomas Moors
    Aug 15 at 13:25










  • ... and that file in user1's home directory is owned by another user?
    – Kusalananda
    Aug 15 at 13:26















@Kusalananda yes the directory is owned by user1:apache. I would suspect the first case would also fail when that was not true.
– Thomas Moors
Aug 15 at 13:16




@Kusalananda yes the directory is owned by user1:apache. I would suspect the first case would also fail when that was not true.
– Thomas Moors
Aug 15 at 13:16




3




3




If your remove the - from the command and do su user1 -c ...? With - you do a full login, and may end up in another directory than the directory you're currently in.
– Kusalananda
Aug 15 at 13:21




If your remove the - from the command and do su user1 -c ...? With - you do a full login, and may end up in another directory than the directory you're currently in.
– Kusalananda
Aug 15 at 13:21












@steeldriver That's what I thought. But why would user1 not be able to touch c in their home directory. Is there already a file owned by another user there?
– Kusalananda
Aug 15 at 13:22




@steeldriver That's what I thought. But why would user1 not be able to touch c in their home directory. Is there already a file owned by another user there?
– Kusalananda
Aug 15 at 13:22












@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google: su - user1 -c changed the current working directory!
– Thomas Moors
Aug 15 at 13:25




@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google: su - user1 -c changed the current working directory!
– Thomas Moors
Aug 15 at 13:25












... and that file in user1's home directory is owned by another user?
– Kusalananda
Aug 15 at 13:26




... and that file in user1's home directory is owned by another user?
– Kusalananda
Aug 15 at 13:26










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










When you do su - username you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c in this way, you therefore try to run that command in the user's home directory.



Instead, drop the - from the command line:



su user1 -c "touch c"


This would execute touch c as user1 in the current directory.




Speculation:



The original su - command failed because there is already a file called c in user1's home directory owned by another user.






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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f462745%2fwhy-is-there-a-different-result-when-running-as-user1-and-su-user1-c-command%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    When you do su - username you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c in this way, you therefore try to run that command in the user's home directory.



    Instead, drop the - from the command line:



    su user1 -c "touch c"


    This would execute touch c as user1 in the current directory.




    Speculation:



    The original su - command failed because there is already a file called c in user1's home directory owned by another user.






    share|improve this answer


























      up vote
      4
      down vote



      accepted










      When you do su - username you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c in this way, you therefore try to run that command in the user's home directory.



      Instead, drop the - from the command line:



      su user1 -c "touch c"


      This would execute touch c as user1 in the current directory.




      Speculation:



      The original su - command failed because there is already a file called c in user1's home directory owned by another user.






      share|improve this answer
























        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        When you do su - username you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c in this way, you therefore try to run that command in the user's home directory.



        Instead, drop the - from the command line:



        su user1 -c "touch c"


        This would execute touch c as user1 in the current directory.




        Speculation:



        The original su - command failed because there is already a file called c in user1's home directory owned by another user.






        share|improve this answer














        When you do su - username you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c in this way, you therefore try to run that command in the user's home directory.



        Instead, drop the - from the command line:



        su user1 -c "touch c"


        This would execute touch c as user1 in the current directory.




        Speculation:



        The original su - command failed because there is already a file called c in user1's home directory owned by another user.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 15 at 13:33

























        answered Aug 15 at 13:27









        Kusalananda

        106k14209327




        106k14209327



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462745%2fwhy-is-there-a-different-result-when-running-as-user1-and-su-user1-c-command%23new-answer', 'question_page');

            );

            Post as a guest













































































            V,G ZIOAJlQ 6HIOd,kYizgnp7IK7FWE3N,jyxPK9v,vuVepfwapTfgU,v,oOwY4 PsDklQw
            4A0M onA7JhynyT7S2 MHjClNxmFqNjRaH,Ukc xfeZ6c,Ta 37FTbSfhT,XKGz

            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            How many registers does an x86_64 CPU actually have?

            Displaying single band from multi-band raster using QGIS