How to set user passwords using passwd without a prompt?











up vote
15
down vote

favorite
1












I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?



Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.










share|improve this question




























    up vote
    15
    down vote

    favorite
    1












    I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?



    Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.










    share|improve this question


























      up vote
      15
      down vote

      favorite
      1









      up vote
      15
      down vote

      favorite
      1






      1





      I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?



      Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.










      share|improve this question















      I am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?



      Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.







      password






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 1 '16 at 4:09









      muru

      135k20289492




      135k20289492










      asked Nov 18 '11 at 11:06









      Jake Petroules

      178116




      178116






















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          16
          down vote



          accepted










          Try usermod:



          usermod --password PASSWORD USERNAME


          The only thing is this needs a pre-encrypted password string which you'd have to generate first.






          share|improve this answer

















          • 1




            ...which I can generate using mkpasswd. Excellent, thanks!
            – Jake Petroules
            Nov 18 '11 at 11:27






          • 13




            You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
            – Eric Smith
            Jan 16 '15 at 19:34










          • Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work: usermod --password $(openssl passwd -1 {password}) {username}
            – BoCoKeith
            Nov 29 at 15:36




















          up vote
          6
          down vote













          You should look at the chpasswd command (if available in your linux flavor):



          echo 'userid:newpasswd' | chpasswd


          Or, you can cat a file listing userid:passwd for each account on a separate line.



          That's it.






          share|improve this answer






























            up vote
            0
            down vote













            You should use password aging, and set the users so that they must change their password on the first login. See this article.






            share|improve this answer





















            • These intended to be FTP-only accounts, but good advice. ;)
              – Jake Petroules
              Nov 18 '11 at 22:49


















            up vote
            0
            down vote













            Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.



            $ openssl passwd -1 -salt 5RPVAd clear-text-passwd43



            $1$5RPVAd$vgsoSANybLDepv2ETcUH7.



            Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.



            $ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root



            Check it out in shadow file.



            $ grep root /etc/shadow



            root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::






            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              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: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2faskubuntu.com%2fquestions%2f80444%2fhow-to-set-user-passwords-using-passwd-without-a-prompt%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              16
              down vote



              accepted










              Try usermod:



              usermod --password PASSWORD USERNAME


              The only thing is this needs a pre-encrypted password string which you'd have to generate first.






              share|improve this answer

















              • 1




                ...which I can generate using mkpasswd. Excellent, thanks!
                – Jake Petroules
                Nov 18 '11 at 11:27






              • 13




                You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
                – Eric Smith
                Jan 16 '15 at 19:34










              • Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work: usermod --password $(openssl passwd -1 {password}) {username}
                – BoCoKeith
                Nov 29 at 15:36

















              up vote
              16
              down vote



              accepted










              Try usermod:



              usermod --password PASSWORD USERNAME


              The only thing is this needs a pre-encrypted password string which you'd have to generate first.






              share|improve this answer

















              • 1




                ...which I can generate using mkpasswd. Excellent, thanks!
                – Jake Petroules
                Nov 18 '11 at 11:27






              • 13




                You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
                – Eric Smith
                Jan 16 '15 at 19:34










              • Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work: usermod --password $(openssl passwd -1 {password}) {username}
                – BoCoKeith
                Nov 29 at 15:36















              up vote
              16
              down vote



              accepted







              up vote
              16
              down vote



              accepted






              Try usermod:



              usermod --password PASSWORD USERNAME


              The only thing is this needs a pre-encrypted password string which you'd have to generate first.






              share|improve this answer












              Try usermod:



              usermod --password PASSWORD USERNAME


              The only thing is this needs a pre-encrypted password string which you'd have to generate first.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 18 '11 at 11:18









              Caesium

              11.3k33147




              11.3k33147








              • 1




                ...which I can generate using mkpasswd. Excellent, thanks!
                – Jake Petroules
                Nov 18 '11 at 11:27






              • 13




                You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
                – Eric Smith
                Jan 16 '15 at 19:34










              • Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work: usermod --password $(openssl passwd -1 {password}) {username}
                – BoCoKeith
                Nov 29 at 15:36
















              • 1




                ...which I can generate using mkpasswd. Excellent, thanks!
                – Jake Petroules
                Nov 18 '11 at 11:27






              • 13




                You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
                – Eric Smith
                Jan 16 '15 at 19:34










              • Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work: usermod --password $(openssl passwd -1 {password}) {username}
                – BoCoKeith
                Nov 29 at 15:36










              1




              1




              ...which I can generate using mkpasswd. Excellent, thanks!
              – Jake Petroules
              Nov 18 '11 at 11:27




              ...which I can generate using mkpasswd. Excellent, thanks!
              – Jake Petroules
              Nov 18 '11 at 11:27




              13




              13




              You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
              – Eric Smith
              Jan 16 '15 at 19:34




              You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME
              – Eric Smith
              Jan 16 '15 at 19:34












              Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work: usermod --password $(openssl passwd -1 {password}) {username}
              – BoCoKeith
              Nov 29 at 15:36






              Three years too late. I couldn't make the answer @EricSmith, but I did discover a simpler version of the command that did work: usermod --password $(openssl passwd -1 {password}) {username}
              – BoCoKeith
              Nov 29 at 15:36














              up vote
              6
              down vote













              You should look at the chpasswd command (if available in your linux flavor):



              echo 'userid:newpasswd' | chpasswd


              Or, you can cat a file listing userid:passwd for each account on a separate line.



              That's it.






              share|improve this answer



























                up vote
                6
                down vote













                You should look at the chpasswd command (if available in your linux flavor):



                echo 'userid:newpasswd' | chpasswd


                Or, you can cat a file listing userid:passwd for each account on a separate line.



                That's it.






                share|improve this answer

























                  up vote
                  6
                  down vote










                  up vote
                  6
                  down vote









                  You should look at the chpasswd command (if available in your linux flavor):



                  echo 'userid:newpasswd' | chpasswd


                  Or, you can cat a file listing userid:passwd for each account on a separate line.



                  That's it.






                  share|improve this answer














                  You should look at the chpasswd command (if available in your linux flavor):



                  echo 'userid:newpasswd' | chpasswd


                  Or, you can cat a file listing userid:passwd for each account on a separate line.



                  That's it.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 2 '14 at 21:22









                  Eric Carvalho

                  41.1k17113144




                  41.1k17113144










                  answered Jan 2 '14 at 21:02









                  Allan

                  6111




                  6111






















                      up vote
                      0
                      down vote













                      You should use password aging, and set the users so that they must change their password on the first login. See this article.






                      share|improve this answer





















                      • These intended to be FTP-only accounts, but good advice. ;)
                        – Jake Petroules
                        Nov 18 '11 at 22:49















                      up vote
                      0
                      down vote













                      You should use password aging, and set the users so that they must change their password on the first login. See this article.






                      share|improve this answer





















                      • These intended to be FTP-only accounts, but good advice. ;)
                        – Jake Petroules
                        Nov 18 '11 at 22:49













                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      You should use password aging, and set the users so that they must change their password on the first login. See this article.






                      share|improve this answer












                      You should use password aging, and set the users so that they must change their password on the first login. See this article.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 18 '11 at 21:37









                      waltinator

                      21.8k74169




                      21.8k74169












                      • These intended to be FTP-only accounts, but good advice. ;)
                        – Jake Petroules
                        Nov 18 '11 at 22:49


















                      • These intended to be FTP-only accounts, but good advice. ;)
                        – Jake Petroules
                        Nov 18 '11 at 22:49
















                      These intended to be FTP-only accounts, but good advice. ;)
                      – Jake Petroules
                      Nov 18 '11 at 22:49




                      These intended to be FTP-only accounts, but good advice. ;)
                      – Jake Petroules
                      Nov 18 '11 at 22:49










                      up vote
                      0
                      down vote













                      Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.



                      $ openssl passwd -1 -salt 5RPVAd clear-text-passwd43



                      $1$5RPVAd$vgsoSANybLDepv2ETcUH7.



                      Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.



                      $ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root



                      Check it out in shadow file.



                      $ grep root /etc/shadow



                      root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.



                        $ openssl passwd -1 -salt 5RPVAd clear-text-passwd43



                        $1$5RPVAd$vgsoSANybLDepv2ETcUH7.



                        Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.



                        $ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root



                        Check it out in shadow file.



                        $ grep root /etc/shadow



                        root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.



                          $ openssl passwd -1 -salt 5RPVAd clear-text-passwd43



                          $1$5RPVAd$vgsoSANybLDepv2ETcUH7.



                          Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.



                          $ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root



                          Check it out in shadow file.



                          $ grep root /etc/shadow



                          root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::






                          share|improve this answer












                          Inspired by Eric Smith's idea, combining "openssl passwd" and "usermod -p" command worked. Generate hashed value of password along with salt value.



                          $ openssl passwd -1 -salt 5RPVAd clear-text-passwd43



                          $1$5RPVAd$vgsoSANybLDepv2ETcUH7.



                          Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.



                          $ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root



                          Check it out in shadow file.



                          $ grep root /etc/shadow



                          root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 31 at 21:29









                          Joon Byun

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • 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%2faskubuntu.com%2fquestions%2f80444%2fhow-to-set-user-passwords-using-passwd-without-a-prompt%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







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                               ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕