Linux command for switching user with password as parameter

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











up vote
1
down vote

favorite












I want to write the Linux shell script that switches the user without asking for password, i.e. password can be specified as the parameter.



I have my script like this startService.sh



sudo su hduser -p mypassword


but this is not working.



Can anyone tell how to specify the password in the command itself?










share|improve this question



























    up vote
    1
    down vote

    favorite












    I want to write the Linux shell script that switches the user without asking for password, i.e. password can be specified as the parameter.



    I have my script like this startService.sh



    sudo su hduser -p mypassword


    but this is not working.



    Can anyone tell how to specify the password in the command itself?










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I want to write the Linux shell script that switches the user without asking for password, i.e. password can be specified as the parameter.



      I have my script like this startService.sh



      sudo su hduser -p mypassword


      but this is not working.



      Can anyone tell how to specify the password in the command itself?










      share|improve this question















      I want to write the Linux shell script that switches the user without asking for password, i.e. password can be specified as the parameter.



      I have my script like this startService.sh



      sudo su hduser -p mypassword


      but this is not working.



      Can anyone tell how to specify the password in the command itself?







      shell-script sudo users






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 14 at 14:22









      Vlastimil

      6,4861148121




      6,4861148121










      asked Sep 26 '17 at 4:21









      Akash Sethi

      130116




      130116




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          You could use the -S switch which reads the password from standard input like this:



          echo 'password' | sudo -S command


          From the man page:




          -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.




          But there's a catch. It works for the current user only. I can't find a way around it, at least.






          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%2f394455%2flinux-command-for-switching-user-with-password-as-parameter%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
            0
            down vote



            accepted










            You could use the -S switch which reads the password from standard input like this:



            echo 'password' | sudo -S command


            From the man page:




            -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.




            But there's a catch. It works for the current user only. I can't find a way around it, at least.






            share|improve this answer


























              up vote
              0
              down vote



              accepted










              You could use the -S switch which reads the password from standard input like this:



              echo 'password' | sudo -S command


              From the man page:




              -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.




              But there's a catch. It works for the current user only. I can't find a way around it, at least.






              share|improve this answer
























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                You could use the -S switch which reads the password from standard input like this:



                echo 'password' | sudo -S command


                From the man page:




                -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.




                But there's a catch. It works for the current user only. I can't find a way around it, at least.






                share|improve this answer














                You could use the -S switch which reads the password from standard input like this:



                echo 'password' | sudo -S command


                From the man page:




                -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.




                But there's a catch. It works for the current user only. I can't find a way around it, at least.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jun 14 at 15:32

























                answered Sep 26 '17 at 4:53









                Vlastimil

                6,4861148121




                6,4861148121



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394455%2flinux-command-for-switching-user-with-password-as-parameter%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

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

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?