How do I include a password with SSH command? (want to make shell script)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.










share|improve this question


















  • 2





    This still is valid: askubuntu.com/questions/46930/… :)

    – Rinzwind
    Dec 1 '12 at 9:38











  • How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get: Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'

    – Eva
    Dec 1 '12 at 9:55













  • Create a new question for the TCP-port thing.

    – jippie
    Dec 1 '12 at 10:07











  • askubuntu.com/questions/224190/…

    – Eva
    Dec 1 '12 at 10:18


















3















I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.










share|improve this question


















  • 2





    This still is valid: askubuntu.com/questions/46930/… :)

    – Rinzwind
    Dec 1 '12 at 9:38











  • How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get: Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'

    – Eva
    Dec 1 '12 at 9:55













  • Create a new question for the TCP-port thing.

    – jippie
    Dec 1 '12 at 10:07











  • askubuntu.com/questions/224190/…

    – Eva
    Dec 1 '12 at 10:18














3












3








3








I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.










share|improve this question














I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.







bash ssh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 1 '12 at 9:35









EvaEva

3982610




3982610








  • 2





    This still is valid: askubuntu.com/questions/46930/… :)

    – Rinzwind
    Dec 1 '12 at 9:38











  • How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get: Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'

    – Eva
    Dec 1 '12 at 9:55













  • Create a new question for the TCP-port thing.

    – jippie
    Dec 1 '12 at 10:07











  • askubuntu.com/questions/224190/…

    – Eva
    Dec 1 '12 at 10:18














  • 2





    This still is valid: askubuntu.com/questions/46930/… :)

    – Rinzwind
    Dec 1 '12 at 9:38











  • How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get: Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'

    – Eva
    Dec 1 '12 at 9:55













  • Create a new question for the TCP-port thing.

    – jippie
    Dec 1 '12 at 10:07











  • askubuntu.com/questions/224190/…

    – Eva
    Dec 1 '12 at 10:18








2




2





This still is valid: askubuntu.com/questions/46930/… :)

– Rinzwind
Dec 1 '12 at 9:38





This still is valid: askubuntu.com/questions/46930/… :)

– Rinzwind
Dec 1 '12 at 9:38













How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get: Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'

– Eva
Dec 1 '12 at 9:55







How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get: Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'

– Eva
Dec 1 '12 at 9:55















Create a new question for the TCP-port thing.

– jippie
Dec 1 '12 at 10:07





Create a new question for the TCP-port thing.

– jippie
Dec 1 '12 at 10:07













askubuntu.com/questions/224190/…

– Eva
Dec 1 '12 at 10:18





askubuntu.com/questions/224190/…

– Eva
Dec 1 '12 at 10:18










3 Answers
3






active

oldest

votes


















2














I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.



Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.






share|improve this answer































    1














    I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.



    The procedure is explained here.






    share|improve this answer































      0














      This thread on ServerFault suggests two ways, one with sshpass:



      sudo apt-get install sshpass
      sshpass -p your_password ssh user@hostname


      and one with expect:



      #!/usr/bin/expect -f
      # ./ssh.exp password 192.168.1.11 id
      set pass [lrange $argv 0 0]
      set server [lrange $argv 1 1]
      set name [lrange $argv 2 2]

      spawn ssh $name@$server
      match_max 100000
      expect "*?assword:*"
      send -- "$passr"
      send -- "r"
      interact





      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',
        autoActivateHeartbeat: false,
        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%2f224181%2fhow-do-i-include-a-password-with-ssh-command-want-to-make-shell-script%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.



        Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.






        share|improve this answer




























          2














          I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.



          Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.






          share|improve this answer


























            2












            2








            2







            I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.



            Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.






            share|improve this answer













            I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.



            Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 2 '12 at 6:40









            Scott SeveranceScott Severance

            10.5k73669




            10.5k73669

























                1














                I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.



                The procedure is explained here.






                share|improve this answer




























                  1














                  I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.



                  The procedure is explained here.






                  share|improve this answer


























                    1












                    1








                    1







                    I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.



                    The procedure is explained here.






                    share|improve this answer













                    I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.



                    The procedure is explained here.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 6 '12 at 22:47









                    hazizhaziz

                    1,53752843




                    1,53752843























                        0














                        This thread on ServerFault suggests two ways, one with sshpass:



                        sudo apt-get install sshpass
                        sshpass -p your_password ssh user@hostname


                        and one with expect:



                        #!/usr/bin/expect -f
                        # ./ssh.exp password 192.168.1.11 id
                        set pass [lrange $argv 0 0]
                        set server [lrange $argv 1 1]
                        set name [lrange $argv 2 2]

                        spawn ssh $name@$server
                        match_max 100000
                        expect "*?assword:*"
                        send -- "$passr"
                        send -- "r"
                        interact





                        share|improve this answer




























                          0














                          This thread on ServerFault suggests two ways, one with sshpass:



                          sudo apt-get install sshpass
                          sshpass -p your_password ssh user@hostname


                          and one with expect:



                          #!/usr/bin/expect -f
                          # ./ssh.exp password 192.168.1.11 id
                          set pass [lrange $argv 0 0]
                          set server [lrange $argv 1 1]
                          set name [lrange $argv 2 2]

                          spawn ssh $name@$server
                          match_max 100000
                          expect "*?assword:*"
                          send -- "$passr"
                          send -- "r"
                          interact





                          share|improve this answer


























                            0












                            0








                            0







                            This thread on ServerFault suggests two ways, one with sshpass:



                            sudo apt-get install sshpass
                            sshpass -p your_password ssh user@hostname


                            and one with expect:



                            #!/usr/bin/expect -f
                            # ./ssh.exp password 192.168.1.11 id
                            set pass [lrange $argv 0 0]
                            set server [lrange $argv 1 1]
                            set name [lrange $argv 2 2]

                            spawn ssh $name@$server
                            match_max 100000
                            expect "*?assword:*"
                            send -- "$passr"
                            send -- "r"
                            interact





                            share|improve this answer













                            This thread on ServerFault suggests two ways, one with sshpass:



                            sudo apt-get install sshpass
                            sshpass -p your_password ssh user@hostname


                            and one with expect:



                            #!/usr/bin/expect -f
                            # ./ssh.exp password 192.168.1.11 id
                            set pass [lrange $argv 0 0]
                            set server [lrange $argv 1 1]
                            set name [lrange $argv 2 2]

                            spawn ssh $name@$server
                            match_max 100000
                            expect "*?assword:*"
                            send -- "$passr"
                            send -- "r"
                            interact






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 28 at 17:26









                            mmorinmmorin

                            1949




                            1949






























                                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.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f224181%2fhow-do-i-include-a-password-with-ssh-command-want-to-make-shell-script%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

                                How did Captain America manage to do this?

                                迪纳利

                                南乌拉尔铁路局