How to use scp in a bash script without specifying password?File encryption in a bash script without...

How does a predictive coding aid in lossless compression?

Expand and Contract

How can I determine if the org that I'm currently connected to is a scratch org?

Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?

How to tell a function to use the default argument values?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

Ambiguity in the definition of entropy

Should I cover my bicycle overnight while bikepacking?

Is it possible to create a QR code using text?

How do I gain back my faith in my PhD degree?

Arrow those variables!

Intersection Puzzle

I would say: "You are another teacher", but she is a woman and I am a man

Reverse dictionary where values are lists

Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?

How seriously should I take size and weight limits of hand luggage?

A category-like structure without composition?

iPad being using in wall mount battery swollen

Are there any examples of a variable being normally distributed that is *not* due to the Central Limit Theorem?

Plagiarism or not?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Can we compute the area of a quadrilateral with one right angle when we only know the lengths of any three sides?

Do UK voters know if their MP will be the Speaker of the House?



How to use scp in a bash script without specifying password?


File encryption in a bash script without explicity providing passwordRunning bash script that uses ssh and scp (prompts for password) securelyUpload file with SCP bash scriptaescrypt doesn't function with pv in pipelineHow to execute bash script without password?ssh without password from a bash scriptHow to scp without password prompt without storing private keyHow to scp-and-ssh with specifying host twice?SCP Hidden Password Promptrun ssh / scp from bash script w/out password - key installed













3















I am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp?



Currently, I am doing this manually, by using scp. The remote server always prompts me for the password, and I supply that. I want to automate this (hence the bash script). However, I dont want to supply my password in plain text (or if at all - I was under the impression that open SSL does away with passwords and uses certificates etc?).



Can anyone please explain how I can automate my current process, without explicitly displaying my password.



I am running on Ubuntu 10.0.4










share|improve this question



























    3















    I am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp?



    Currently, I am doing this manually, by using scp. The remote server always prompts me for the password, and I supply that. I want to automate this (hence the bash script). However, I dont want to supply my password in plain text (or if at all - I was under the impression that open SSL does away with passwords and uses certificates etc?).



    Can anyone please explain how I can automate my current process, without explicitly displaying my password.



    I am running on Ubuntu 10.0.4










    share|improve this question

























      3












      3








      3








      I am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp?



      Currently, I am doing this manually, by using scp. The remote server always prompts me for the password, and I supply that. I want to automate this (hence the bash script). However, I dont want to supply my password in plain text (or if at all - I was under the impression that open SSL does away with passwords and uses certificates etc?).



      Can anyone please explain how I can automate my current process, without explicitly displaying my password.



      I am running on Ubuntu 10.0.4










      share|improve this question














      I am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp?



      Currently, I am doing this manually, by using scp. The remote server always prompts me for the password, and I supply that. I want to automate this (hence the bash script). However, I dont want to supply my password in plain text (or if at all - I was under the impression that open SSL does away with passwords and uses certificates etc?).



      Can anyone please explain how I can automate my current process, without explicitly displaying my password.



      I am running on Ubuntu 10.0.4







      linux ubuntu bash scp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 30 '10 at 9:55









      morpheousmorpheous

      1,63892628




      1,63892628






















          3 Answers
          3






          active

          oldest

          votes


















          7














          To login without password you need to setup key-based authentication. There are a number of tutorials out there - this one looks like a good place to start (edit: the original site fell of the Internet, this link is to the last copy archived by the WayBackMachine).



          If you put a passphrase on your key (recommended) you will still need to provide that when you login but you can use ssh-agent to reduce the amount of times you have to provide it.



          If you need scripts that use SSH/SCP to run unattended then you need to not have a passphrase on your key, but in this case you absolutely must keep that key file secure such that no-one else can read it otherwise they will be able to authenticate on that server as you without any password/passphrase.






          share|improve this answer





















          • 1





            ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?

            – Stephen
            Mar 29 '11 at 1:44











          • I've updated the link to point to a copy archived by the WayBackMachine.

            – David Spillett
            Mar 29 '11 at 15:44











          • was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.

            – TheVillageIdiot
            Jun 8 '11 at 17:01



















          0














          supply a password to scp



          Piping your password to the standard input of scp won't work:



          echo "password" | scp file user@host:/dir/to/copy/to


          because scp doesn't read from the standard input for security reasons.



          Use the tool sshpass instead:



          You may have to install sshpass as root since it is non standard.



          sshpass -p 'mypassword' scp -r el@myserv.com:/home/a/moo.txt /home/b/bar.txt





          share|improve this answer































            0














            If you use a key like .pem etc (so you wouldn't have to have a password) you could use this



            here's bash code for SCP with a .pem key file.
            Just save it to a script.sh file then run with 'sh script.sh'



            Enjoy



            #!/bin/bash
            #Error function
            function die(){
            echo "$1"
            exit 1
            }

            Host=ec2-53-298-45-63.us-west-1.compute.amazonaws.com
            User=ubuntu
            #Directory at sent destination
            SendDirectory=scp
            #File to send at host
            FileName=filetosend.txt
            #Key file
            Key=MyKeyFile.pem

            echo "Aperture in Process...";

            scp -i $Key $FileName $User@$Host:$SendDirectory ||
            die "@@@@@@@Houston we have problem"

            echo "########Aperture Complete#########";




            share








            New contributor




            Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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%2fsuperuser.com%2fquestions%2f169808%2fhow-to-use-scp-in-a-bash-script-without-specifying-password%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









              7














              To login without password you need to setup key-based authentication. There are a number of tutorials out there - this one looks like a good place to start (edit: the original site fell of the Internet, this link is to the last copy archived by the WayBackMachine).



              If you put a passphrase on your key (recommended) you will still need to provide that when you login but you can use ssh-agent to reduce the amount of times you have to provide it.



              If you need scripts that use SSH/SCP to run unattended then you need to not have a passphrase on your key, but in this case you absolutely must keep that key file secure such that no-one else can read it otherwise they will be able to authenticate on that server as you without any password/passphrase.






              share|improve this answer





















              • 1





                ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?

                – Stephen
                Mar 29 '11 at 1:44











              • I've updated the link to point to a copy archived by the WayBackMachine.

                – David Spillett
                Mar 29 '11 at 15:44











              • was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.

                – TheVillageIdiot
                Jun 8 '11 at 17:01
















              7














              To login without password you need to setup key-based authentication. There are a number of tutorials out there - this one looks like a good place to start (edit: the original site fell of the Internet, this link is to the last copy archived by the WayBackMachine).



              If you put a passphrase on your key (recommended) you will still need to provide that when you login but you can use ssh-agent to reduce the amount of times you have to provide it.



              If you need scripts that use SSH/SCP to run unattended then you need to not have a passphrase on your key, but in this case you absolutely must keep that key file secure such that no-one else can read it otherwise they will be able to authenticate on that server as you without any password/passphrase.






              share|improve this answer





















              • 1





                ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?

                – Stephen
                Mar 29 '11 at 1:44











              • I've updated the link to point to a copy archived by the WayBackMachine.

                – David Spillett
                Mar 29 '11 at 15:44











              • was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.

                – TheVillageIdiot
                Jun 8 '11 at 17:01














              7












              7








              7







              To login without password you need to setup key-based authentication. There are a number of tutorials out there - this one looks like a good place to start (edit: the original site fell of the Internet, this link is to the last copy archived by the WayBackMachine).



              If you put a passphrase on your key (recommended) you will still need to provide that when you login but you can use ssh-agent to reduce the amount of times you have to provide it.



              If you need scripts that use SSH/SCP to run unattended then you need to not have a passphrase on your key, but in this case you absolutely must keep that key file secure such that no-one else can read it otherwise they will be able to authenticate on that server as you without any password/passphrase.






              share|improve this answer















              To login without password you need to setup key-based authentication. There are a number of tutorials out there - this one looks like a good place to start (edit: the original site fell of the Internet, this link is to the last copy archived by the WayBackMachine).



              If you put a passphrase on your key (recommended) you will still need to provide that when you login but you can use ssh-agent to reduce the amount of times you have to provide it.



              If you need scripts that use SSH/SCP to run unattended then you need to not have a passphrase on your key, but in this case you absolutely must keep that key file secure such that no-one else can read it otherwise they will be able to authenticate on that server as you without any password/passphrase.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 29 '11 at 15:44

























              answered Jul 30 '10 at 10:14









              David SpillettDavid Spillett

              21.9k4062




              21.9k4062








              • 1





                ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?

                – Stephen
                Mar 29 '11 at 1:44











              • I've updated the link to point to a copy archived by the WayBackMachine.

                – David Spillett
                Mar 29 '11 at 15:44











              • was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.

                – TheVillageIdiot
                Jun 8 '11 at 17:01














              • 1





                ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?

                – Stephen
                Mar 29 '11 at 1:44











              • I've updated the link to point to a copy archived by the WayBackMachine.

                – David Spillett
                Mar 29 '11 at 15:44











              • was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.

                – TheVillageIdiot
                Jun 8 '11 at 17:01








              1




              1





              ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?

              – Stephen
              Mar 29 '11 at 1:44





              ...and it's dead - was it hostingrails.com/HowTo-SSH-SCP-without-a-password or is there a better page?

              – Stephen
              Mar 29 '11 at 1:44













              I've updated the link to point to a copy archived by the WayBackMachine.

              – David Spillett
              Mar 29 '11 at 15:44





              I've updated the link to point to a copy archived by the WayBackMachine.

              – David Spillett
              Mar 29 '11 at 15:44













              was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.

              – TheVillageIdiot
              Jun 8 '11 at 17:01





              was going to ask just this question as I am being prompted for passphrase :D will have to setup keys without passphrase now.

              – TheVillageIdiot
              Jun 8 '11 at 17:01













              0














              supply a password to scp



              Piping your password to the standard input of scp won't work:



              echo "password" | scp file user@host:/dir/to/copy/to


              because scp doesn't read from the standard input for security reasons.



              Use the tool sshpass instead:



              You may have to install sshpass as root since it is non standard.



              sshpass -p 'mypassword' scp -r el@myserv.com:/home/a/moo.txt /home/b/bar.txt





              share|improve this answer




























                0














                supply a password to scp



                Piping your password to the standard input of scp won't work:



                echo "password" | scp file user@host:/dir/to/copy/to


                because scp doesn't read from the standard input for security reasons.



                Use the tool sshpass instead:



                You may have to install sshpass as root since it is non standard.



                sshpass -p 'mypassword' scp -r el@myserv.com:/home/a/moo.txt /home/b/bar.txt





                share|improve this answer


























                  0












                  0








                  0







                  supply a password to scp



                  Piping your password to the standard input of scp won't work:



                  echo "password" | scp file user@host:/dir/to/copy/to


                  because scp doesn't read from the standard input for security reasons.



                  Use the tool sshpass instead:



                  You may have to install sshpass as root since it is non standard.



                  sshpass -p 'mypassword' scp -r el@myserv.com:/home/a/moo.txt /home/b/bar.txt





                  share|improve this answer













                  supply a password to scp



                  Piping your password to the standard input of scp won't work:



                  echo "password" | scp file user@host:/dir/to/copy/to


                  because scp doesn't read from the standard input for security reasons.



                  Use the tool sshpass instead:



                  You may have to install sshpass as root since it is non standard.



                  sshpass -p 'mypassword' scp -r el@myserv.com:/home/a/moo.txt /home/b/bar.txt






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 12 '12 at 4:28









                  Eric LeschinskiEric Leschinski

                  4,30343646




                  4,30343646























                      0














                      If you use a key like .pem etc (so you wouldn't have to have a password) you could use this



                      here's bash code for SCP with a .pem key file.
                      Just save it to a script.sh file then run with 'sh script.sh'



                      Enjoy



                      #!/bin/bash
                      #Error function
                      function die(){
                      echo "$1"
                      exit 1
                      }

                      Host=ec2-53-298-45-63.us-west-1.compute.amazonaws.com
                      User=ubuntu
                      #Directory at sent destination
                      SendDirectory=scp
                      #File to send at host
                      FileName=filetosend.txt
                      #Key file
                      Key=MyKeyFile.pem

                      echo "Aperture in Process...";

                      scp -i $Key $FileName $User@$Host:$SendDirectory ||
                      die "@@@@@@@Houston we have problem"

                      echo "########Aperture Complete#########";




                      share








                      New contributor




                      Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        If you use a key like .pem etc (so you wouldn't have to have a password) you could use this



                        here's bash code for SCP with a .pem key file.
                        Just save it to a script.sh file then run with 'sh script.sh'



                        Enjoy



                        #!/bin/bash
                        #Error function
                        function die(){
                        echo "$1"
                        exit 1
                        }

                        Host=ec2-53-298-45-63.us-west-1.compute.amazonaws.com
                        User=ubuntu
                        #Directory at sent destination
                        SendDirectory=scp
                        #File to send at host
                        FileName=filetosend.txt
                        #Key file
                        Key=MyKeyFile.pem

                        echo "Aperture in Process...";

                        scp -i $Key $FileName $User@$Host:$SendDirectory ||
                        die "@@@@@@@Houston we have problem"

                        echo "########Aperture Complete#########";




                        share








                        New contributor




                        Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          If you use a key like .pem etc (so you wouldn't have to have a password) you could use this



                          here's bash code for SCP with a .pem key file.
                          Just save it to a script.sh file then run with 'sh script.sh'



                          Enjoy



                          #!/bin/bash
                          #Error function
                          function die(){
                          echo "$1"
                          exit 1
                          }

                          Host=ec2-53-298-45-63.us-west-1.compute.amazonaws.com
                          User=ubuntu
                          #Directory at sent destination
                          SendDirectory=scp
                          #File to send at host
                          FileName=filetosend.txt
                          #Key file
                          Key=MyKeyFile.pem

                          echo "Aperture in Process...";

                          scp -i $Key $FileName $User@$Host:$SendDirectory ||
                          die "@@@@@@@Houston we have problem"

                          echo "########Aperture Complete#########";




                          share








                          New contributor




                          Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          If you use a key like .pem etc (so you wouldn't have to have a password) you could use this



                          here's bash code for SCP with a .pem key file.
                          Just save it to a script.sh file then run with 'sh script.sh'



                          Enjoy



                          #!/bin/bash
                          #Error function
                          function die(){
                          echo "$1"
                          exit 1
                          }

                          Host=ec2-53-298-45-63.us-west-1.compute.amazonaws.com
                          User=ubuntu
                          #Directory at sent destination
                          SendDirectory=scp
                          #File to send at host
                          FileName=filetosend.txt
                          #Key file
                          Key=MyKeyFile.pem

                          echo "Aperture in Process...";

                          scp -i $Key $FileName $User@$Host:$SendDirectory ||
                          die "@@@@@@@Houston we have problem"

                          echo "########Aperture Complete#########";





                          share








                          New contributor




                          Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.








                          share


                          share






                          New contributor




                          Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 3 mins ago









                          Chief_ArbiterChief_Arbiter

                          1




                          1




                          New contributor




                          Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Chief_Arbiter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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%2fsuperuser.com%2fquestions%2f169808%2fhow-to-use-scp-in-a-bash-script-without-specifying-password%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

                              Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                              VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                              Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...