run ssh / scp from bash script w/out password - key installed





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I try to copy files between two rpi's in the same network. Public key installed as prompted in many tutorials. When directly calling ssh or scp command from the terminal no password is asked. Running the same command from a bash script it askes for a password.



I am puzzled because most people seem to have the problem with running ssh/scp using a key at all - but this works fine. It looks like a terminal/bash difference.



The Script looks like:



script:



#!/bin/bash

sudo scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


It is executed by



$sudo ./script


I appreciate your help!










share|improve this question




















  • 4





    How exactly do you run it from a bash script? and how do you run the script? Please respond by editing the question.

    – Kamil Maciorowski
    Feb 1 at 10:32











  • Have you copied the public key of the root account to the remote machine? sudo ssh-copy-id ...? I'm asking because you're executing your script via sudo.

    – Daniel F
    Feb 2 at 18:35




















0















I try to copy files between two rpi's in the same network. Public key installed as prompted in many tutorials. When directly calling ssh or scp command from the terminal no password is asked. Running the same command from a bash script it askes for a password.



I am puzzled because most people seem to have the problem with running ssh/scp using a key at all - but this works fine. It looks like a terminal/bash difference.



The Script looks like:



script:



#!/bin/bash

sudo scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


It is executed by



$sudo ./script


I appreciate your help!










share|improve this question




















  • 4





    How exactly do you run it from a bash script? and how do you run the script? Please respond by editing the question.

    – Kamil Maciorowski
    Feb 1 at 10:32











  • Have you copied the public key of the root account to the remote machine? sudo ssh-copy-id ...? I'm asking because you're executing your script via sudo.

    – Daniel F
    Feb 2 at 18:35
















0












0








0








I try to copy files between two rpi's in the same network. Public key installed as prompted in many tutorials. When directly calling ssh or scp command from the terminal no password is asked. Running the same command from a bash script it askes for a password.



I am puzzled because most people seem to have the problem with running ssh/scp using a key at all - but this works fine. It looks like a terminal/bash difference.



The Script looks like:



script:



#!/bin/bash

sudo scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


It is executed by



$sudo ./script


I appreciate your help!










share|improve this question
















I try to copy files between two rpi's in the same network. Public key installed as prompted in many tutorials. When directly calling ssh or scp command from the terminal no password is asked. Running the same command from a bash script it askes for a password.



I am puzzled because most people seem to have the problem with running ssh/scp using a key at all - but this works fine. It looks like a terminal/bash difference.



The Script looks like:



script:



#!/bin/bash

sudo scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


It is executed by



$sudo ./script


I appreciate your help!







bash ssh terminal scp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 2 at 18:24









Ljm Dullaart

75428




75428










asked Feb 1 at 10:26









JanMJanM

11




11








  • 4





    How exactly do you run it from a bash script? and how do you run the script? Please respond by editing the question.

    – Kamil Maciorowski
    Feb 1 at 10:32











  • Have you copied the public key of the root account to the remote machine? sudo ssh-copy-id ...? I'm asking because you're executing your script via sudo.

    – Daniel F
    Feb 2 at 18:35
















  • 4





    How exactly do you run it from a bash script? and how do you run the script? Please respond by editing the question.

    – Kamil Maciorowski
    Feb 1 at 10:32











  • Have you copied the public key of the root account to the remote machine? sudo ssh-copy-id ...? I'm asking because you're executing your script via sudo.

    – Daniel F
    Feb 2 at 18:35










4




4





How exactly do you run it from a bash script? and how do you run the script? Please respond by editing the question.

– Kamil Maciorowski
Feb 1 at 10:32





How exactly do you run it from a bash script? and how do you run the script? Please respond by editing the question.

– Kamil Maciorowski
Feb 1 at 10:32













Have you copied the public key of the root account to the remote machine? sudo ssh-copy-id ...? I'm asking because you're executing your script via sudo.

– Daniel F
Feb 2 at 18:35







Have you copied the public key of the root account to the remote machine? sudo ssh-copy-id ...? I'm asking because you're executing your script via sudo.

– Daniel F
Feb 2 at 18:35












2 Answers
2






active

oldest

votes


















0














The problem with all tutorials is that they may follow different methods. What I normally do is the following.



Because you are using sudo (as per edit of the question) to execute your script, your script will run as root. Not as your own user.



That means that you need to add the public key of root (which is in /root/.ssh/id_rsa.pub) from strawberry in the authorized_keys of root on `blueberry ass well!



Suppose we have two Pi's, let's call them strawberry and blueberry. Strawberry is the ssh-client, blueberry is the server. should be replaced with your logon.



On strawberry:



cd
mkdir .ssh
chown <my name> .ssh
chmod 700 .ssh
ssh-keygen
cp .ssh/id_rsa.pub /tmp/nice_filename
sudo -s
cd ~root
mkdir .ssh
chown root .ssh
chmod 700 .ssh
ssh-keygen
cat .ssh/id_rsa.pub >> /tmp/nice_filename
chmod a+r /tmp/nice_filename
exit

scp /tmp/nice_filename blueberry: # and enter the password for blueberry


ssh-keygen may ask for a password. If you really completely trust your environment, you might choose to leave the password empty. If you do not leave the password empty, you will need to provide that password to unlock the key.



So, normally I just enter-through, leaving the password empty.



On blueberry:



cd
mkdir .ssh
chown <my name> .ssh
chmod 700 .ssh
cat nice_filename >> .ssh/authorized_keys
chown <my name> .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
sudo -s
mkdir ~root/.ssh
chown root.root ~root/.ssh
chmod 700 ~root/.ssh
cat nice_filename >> ~root/.ssh/authorized_keys
chown root ~root/.ssh/authorized_keys
chmod 600 ~root/.ssh/authorized_keys


Instead of the cat id_rsa.pub >> .ssh/authorized_keys, you may mv id_rsa.pub .ssh/authorized_keys, but you should only do this if it is really your first key or if you want to remove existing keys.



Next on strawberry:



ssh blueberry ls /tmp
ssh root@blueberry ls /usr
sudo ssh blueberry ls /var


et voila!






share|improve this answer


























  • thanks for your response. this looks identical to one of the tutorials I did (tried multiple). After all of them the direct ssh or scp via comand line worked without any flaws. - the problem is as soon as I try to execute those same lines (scp) via a bash script a password is asked...

    – JanM
    Feb 2 at 11:36













  • How do you launch your script? Under a different user? Did you put a password for unlocking the keys?

    – Ljm Dullaart
    Feb 2 at 11:40











  • @LjmDullaart it is all te same. I didn't use any passwords other than the default pi/pi combo for the root...all was left blank

    – JanM
    Feb 2 at 12:21











  • So you have a folder /root/.ssh drwx------ root root, on blueberry, in which you have the public key from id_rsa.pub root on strawberry in authorized_keys -rw------- root root. On strawberry, you are root when you launch the script. (just to verify). Can you do grep PermitRootLogin /etc/ssh/sshd_config ? (should be yes, if you can ssh fron the cli) Does ssh -v blueberry provide any hints?

    – Ljm Dullaart
    Feb 2 at 12:34











  • So, from the edit of your question, I can see that it is not the same. I've edited the answer to match your expectations, but please also look at my other answer.

    – Ljm Dullaart
    Feb 2 at 14:59





















0














You mess up things while using sudo. Why you use sudo is not clear. Basically, you just seem to want to do:



script:



#!/bin/bash
scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


and launch the script as



./script





share|improve this answer
























    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%2f1400943%2frun-ssh-scp-from-bash-script-w-out-password-key-installed%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem with all tutorials is that they may follow different methods. What I normally do is the following.



    Because you are using sudo (as per edit of the question) to execute your script, your script will run as root. Not as your own user.



    That means that you need to add the public key of root (which is in /root/.ssh/id_rsa.pub) from strawberry in the authorized_keys of root on `blueberry ass well!



    Suppose we have two Pi's, let's call them strawberry and blueberry. Strawberry is the ssh-client, blueberry is the server. should be replaced with your logon.



    On strawberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    ssh-keygen
    cp .ssh/id_rsa.pub /tmp/nice_filename
    sudo -s
    cd ~root
    mkdir .ssh
    chown root .ssh
    chmod 700 .ssh
    ssh-keygen
    cat .ssh/id_rsa.pub >> /tmp/nice_filename
    chmod a+r /tmp/nice_filename
    exit

    scp /tmp/nice_filename blueberry: # and enter the password for blueberry


    ssh-keygen may ask for a password. If you really completely trust your environment, you might choose to leave the password empty. If you do not leave the password empty, you will need to provide that password to unlock the key.



    So, normally I just enter-through, leaving the password empty.



    On blueberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    cat nice_filename >> .ssh/authorized_keys
    chown <my name> .ssh/authorized_keys
    chmod 600 .ssh/authorized_keys
    sudo -s
    mkdir ~root/.ssh
    chown root.root ~root/.ssh
    chmod 700 ~root/.ssh
    cat nice_filename >> ~root/.ssh/authorized_keys
    chown root ~root/.ssh/authorized_keys
    chmod 600 ~root/.ssh/authorized_keys


    Instead of the cat id_rsa.pub >> .ssh/authorized_keys, you may mv id_rsa.pub .ssh/authorized_keys, but you should only do this if it is really your first key or if you want to remove existing keys.



    Next on strawberry:



    ssh blueberry ls /tmp
    ssh root@blueberry ls /usr
    sudo ssh blueberry ls /var


    et voila!






    share|improve this answer


























    • thanks for your response. this looks identical to one of the tutorials I did (tried multiple). After all of them the direct ssh or scp via comand line worked without any flaws. - the problem is as soon as I try to execute those same lines (scp) via a bash script a password is asked...

      – JanM
      Feb 2 at 11:36













    • How do you launch your script? Under a different user? Did you put a password for unlocking the keys?

      – Ljm Dullaart
      Feb 2 at 11:40











    • @LjmDullaart it is all te same. I didn't use any passwords other than the default pi/pi combo for the root...all was left blank

      – JanM
      Feb 2 at 12:21











    • So you have a folder /root/.ssh drwx------ root root, on blueberry, in which you have the public key from id_rsa.pub root on strawberry in authorized_keys -rw------- root root. On strawberry, you are root when you launch the script. (just to verify). Can you do grep PermitRootLogin /etc/ssh/sshd_config ? (should be yes, if you can ssh fron the cli) Does ssh -v blueberry provide any hints?

      – Ljm Dullaart
      Feb 2 at 12:34











    • So, from the edit of your question, I can see that it is not the same. I've edited the answer to match your expectations, but please also look at my other answer.

      – Ljm Dullaart
      Feb 2 at 14:59


















    0














    The problem with all tutorials is that they may follow different methods. What I normally do is the following.



    Because you are using sudo (as per edit of the question) to execute your script, your script will run as root. Not as your own user.



    That means that you need to add the public key of root (which is in /root/.ssh/id_rsa.pub) from strawberry in the authorized_keys of root on `blueberry ass well!



    Suppose we have two Pi's, let's call them strawberry and blueberry. Strawberry is the ssh-client, blueberry is the server. should be replaced with your logon.



    On strawberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    ssh-keygen
    cp .ssh/id_rsa.pub /tmp/nice_filename
    sudo -s
    cd ~root
    mkdir .ssh
    chown root .ssh
    chmod 700 .ssh
    ssh-keygen
    cat .ssh/id_rsa.pub >> /tmp/nice_filename
    chmod a+r /tmp/nice_filename
    exit

    scp /tmp/nice_filename blueberry: # and enter the password for blueberry


    ssh-keygen may ask for a password. If you really completely trust your environment, you might choose to leave the password empty. If you do not leave the password empty, you will need to provide that password to unlock the key.



    So, normally I just enter-through, leaving the password empty.



    On blueberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    cat nice_filename >> .ssh/authorized_keys
    chown <my name> .ssh/authorized_keys
    chmod 600 .ssh/authorized_keys
    sudo -s
    mkdir ~root/.ssh
    chown root.root ~root/.ssh
    chmod 700 ~root/.ssh
    cat nice_filename >> ~root/.ssh/authorized_keys
    chown root ~root/.ssh/authorized_keys
    chmod 600 ~root/.ssh/authorized_keys


    Instead of the cat id_rsa.pub >> .ssh/authorized_keys, you may mv id_rsa.pub .ssh/authorized_keys, but you should only do this if it is really your first key or if you want to remove existing keys.



    Next on strawberry:



    ssh blueberry ls /tmp
    ssh root@blueberry ls /usr
    sudo ssh blueberry ls /var


    et voila!






    share|improve this answer


























    • thanks for your response. this looks identical to one of the tutorials I did (tried multiple). After all of them the direct ssh or scp via comand line worked without any flaws. - the problem is as soon as I try to execute those same lines (scp) via a bash script a password is asked...

      – JanM
      Feb 2 at 11:36













    • How do you launch your script? Under a different user? Did you put a password for unlocking the keys?

      – Ljm Dullaart
      Feb 2 at 11:40











    • @LjmDullaart it is all te same. I didn't use any passwords other than the default pi/pi combo for the root...all was left blank

      – JanM
      Feb 2 at 12:21











    • So you have a folder /root/.ssh drwx------ root root, on blueberry, in which you have the public key from id_rsa.pub root on strawberry in authorized_keys -rw------- root root. On strawberry, you are root when you launch the script. (just to verify). Can you do grep PermitRootLogin /etc/ssh/sshd_config ? (should be yes, if you can ssh fron the cli) Does ssh -v blueberry provide any hints?

      – Ljm Dullaart
      Feb 2 at 12:34











    • So, from the edit of your question, I can see that it is not the same. I've edited the answer to match your expectations, but please also look at my other answer.

      – Ljm Dullaart
      Feb 2 at 14:59
















    0












    0








    0







    The problem with all tutorials is that they may follow different methods. What I normally do is the following.



    Because you are using sudo (as per edit of the question) to execute your script, your script will run as root. Not as your own user.



    That means that you need to add the public key of root (which is in /root/.ssh/id_rsa.pub) from strawberry in the authorized_keys of root on `blueberry ass well!



    Suppose we have two Pi's, let's call them strawberry and blueberry. Strawberry is the ssh-client, blueberry is the server. should be replaced with your logon.



    On strawberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    ssh-keygen
    cp .ssh/id_rsa.pub /tmp/nice_filename
    sudo -s
    cd ~root
    mkdir .ssh
    chown root .ssh
    chmod 700 .ssh
    ssh-keygen
    cat .ssh/id_rsa.pub >> /tmp/nice_filename
    chmod a+r /tmp/nice_filename
    exit

    scp /tmp/nice_filename blueberry: # and enter the password for blueberry


    ssh-keygen may ask for a password. If you really completely trust your environment, you might choose to leave the password empty. If you do not leave the password empty, you will need to provide that password to unlock the key.



    So, normally I just enter-through, leaving the password empty.



    On blueberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    cat nice_filename >> .ssh/authorized_keys
    chown <my name> .ssh/authorized_keys
    chmod 600 .ssh/authorized_keys
    sudo -s
    mkdir ~root/.ssh
    chown root.root ~root/.ssh
    chmod 700 ~root/.ssh
    cat nice_filename >> ~root/.ssh/authorized_keys
    chown root ~root/.ssh/authorized_keys
    chmod 600 ~root/.ssh/authorized_keys


    Instead of the cat id_rsa.pub >> .ssh/authorized_keys, you may mv id_rsa.pub .ssh/authorized_keys, but you should only do this if it is really your first key or if you want to remove existing keys.



    Next on strawberry:



    ssh blueberry ls /tmp
    ssh root@blueberry ls /usr
    sudo ssh blueberry ls /var


    et voila!






    share|improve this answer















    The problem with all tutorials is that they may follow different methods. What I normally do is the following.



    Because you are using sudo (as per edit of the question) to execute your script, your script will run as root. Not as your own user.



    That means that you need to add the public key of root (which is in /root/.ssh/id_rsa.pub) from strawberry in the authorized_keys of root on `blueberry ass well!



    Suppose we have two Pi's, let's call them strawberry and blueberry. Strawberry is the ssh-client, blueberry is the server. should be replaced with your logon.



    On strawberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    ssh-keygen
    cp .ssh/id_rsa.pub /tmp/nice_filename
    sudo -s
    cd ~root
    mkdir .ssh
    chown root .ssh
    chmod 700 .ssh
    ssh-keygen
    cat .ssh/id_rsa.pub >> /tmp/nice_filename
    chmod a+r /tmp/nice_filename
    exit

    scp /tmp/nice_filename blueberry: # and enter the password for blueberry


    ssh-keygen may ask for a password. If you really completely trust your environment, you might choose to leave the password empty. If you do not leave the password empty, you will need to provide that password to unlock the key.



    So, normally I just enter-through, leaving the password empty.



    On blueberry:



    cd
    mkdir .ssh
    chown <my name> .ssh
    chmod 700 .ssh
    cat nice_filename >> .ssh/authorized_keys
    chown <my name> .ssh/authorized_keys
    chmod 600 .ssh/authorized_keys
    sudo -s
    mkdir ~root/.ssh
    chown root.root ~root/.ssh
    chmod 700 ~root/.ssh
    cat nice_filename >> ~root/.ssh/authorized_keys
    chown root ~root/.ssh/authorized_keys
    chmod 600 ~root/.ssh/authorized_keys


    Instead of the cat id_rsa.pub >> .ssh/authorized_keys, you may mv id_rsa.pub .ssh/authorized_keys, but you should only do this if it is really your first key or if you want to remove existing keys.



    Next on strawberry:



    ssh blueberry ls /tmp
    ssh root@blueberry ls /usr
    sudo ssh blueberry ls /var


    et voila!







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 2 at 14:49

























    answered Feb 1 at 17:01









    Ljm DullaartLjm Dullaart

    75428




    75428













    • thanks for your response. this looks identical to one of the tutorials I did (tried multiple). After all of them the direct ssh or scp via comand line worked without any flaws. - the problem is as soon as I try to execute those same lines (scp) via a bash script a password is asked...

      – JanM
      Feb 2 at 11:36













    • How do you launch your script? Under a different user? Did you put a password for unlocking the keys?

      – Ljm Dullaart
      Feb 2 at 11:40











    • @LjmDullaart it is all te same. I didn't use any passwords other than the default pi/pi combo for the root...all was left blank

      – JanM
      Feb 2 at 12:21











    • So you have a folder /root/.ssh drwx------ root root, on blueberry, in which you have the public key from id_rsa.pub root on strawberry in authorized_keys -rw------- root root. On strawberry, you are root when you launch the script. (just to verify). Can you do grep PermitRootLogin /etc/ssh/sshd_config ? (should be yes, if you can ssh fron the cli) Does ssh -v blueberry provide any hints?

      – Ljm Dullaart
      Feb 2 at 12:34











    • So, from the edit of your question, I can see that it is not the same. I've edited the answer to match your expectations, but please also look at my other answer.

      – Ljm Dullaart
      Feb 2 at 14:59





















    • thanks for your response. this looks identical to one of the tutorials I did (tried multiple). After all of them the direct ssh or scp via comand line worked without any flaws. - the problem is as soon as I try to execute those same lines (scp) via a bash script a password is asked...

      – JanM
      Feb 2 at 11:36













    • How do you launch your script? Under a different user? Did you put a password for unlocking the keys?

      – Ljm Dullaart
      Feb 2 at 11:40











    • @LjmDullaart it is all te same. I didn't use any passwords other than the default pi/pi combo for the root...all was left blank

      – JanM
      Feb 2 at 12:21











    • So you have a folder /root/.ssh drwx------ root root, on blueberry, in which you have the public key from id_rsa.pub root on strawberry in authorized_keys -rw------- root root. On strawberry, you are root when you launch the script. (just to verify). Can you do grep PermitRootLogin /etc/ssh/sshd_config ? (should be yes, if you can ssh fron the cli) Does ssh -v blueberry provide any hints?

      – Ljm Dullaart
      Feb 2 at 12:34











    • So, from the edit of your question, I can see that it is not the same. I've edited the answer to match your expectations, but please also look at my other answer.

      – Ljm Dullaart
      Feb 2 at 14:59



















    thanks for your response. this looks identical to one of the tutorials I did (tried multiple). After all of them the direct ssh or scp via comand line worked without any flaws. - the problem is as soon as I try to execute those same lines (scp) via a bash script a password is asked...

    – JanM
    Feb 2 at 11:36







    thanks for your response. this looks identical to one of the tutorials I did (tried multiple). After all of them the direct ssh or scp via comand line worked without any flaws. - the problem is as soon as I try to execute those same lines (scp) via a bash script a password is asked...

    – JanM
    Feb 2 at 11:36















    How do you launch your script? Under a different user? Did you put a password for unlocking the keys?

    – Ljm Dullaart
    Feb 2 at 11:40





    How do you launch your script? Under a different user? Did you put a password for unlocking the keys?

    – Ljm Dullaart
    Feb 2 at 11:40













    @LjmDullaart it is all te same. I didn't use any passwords other than the default pi/pi combo for the root...all was left blank

    – JanM
    Feb 2 at 12:21





    @LjmDullaart it is all te same. I didn't use any passwords other than the default pi/pi combo for the root...all was left blank

    – JanM
    Feb 2 at 12:21













    So you have a folder /root/.ssh drwx------ root root, on blueberry, in which you have the public key from id_rsa.pub root on strawberry in authorized_keys -rw------- root root. On strawberry, you are root when you launch the script. (just to verify). Can you do grep PermitRootLogin /etc/ssh/sshd_config ? (should be yes, if you can ssh fron the cli) Does ssh -v blueberry provide any hints?

    – Ljm Dullaart
    Feb 2 at 12:34





    So you have a folder /root/.ssh drwx------ root root, on blueberry, in which you have the public key from id_rsa.pub root on strawberry in authorized_keys -rw------- root root. On strawberry, you are root when you launch the script. (just to verify). Can you do grep PermitRootLogin /etc/ssh/sshd_config ? (should be yes, if you can ssh fron the cli) Does ssh -v blueberry provide any hints?

    – Ljm Dullaart
    Feb 2 at 12:34













    So, from the edit of your question, I can see that it is not the same. I've edited the answer to match your expectations, but please also look at my other answer.

    – Ljm Dullaart
    Feb 2 at 14:59







    So, from the edit of your question, I can see that it is not the same. I've edited the answer to match your expectations, but please also look at my other answer.

    – Ljm Dullaart
    Feb 2 at 14:59















    0














    You mess up things while using sudo. Why you use sudo is not clear. Basically, you just seem to want to do:



    script:



    #!/bin/bash
    scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


    and launch the script as



    ./script





    share|improve this answer




























      0














      You mess up things while using sudo. Why you use sudo is not clear. Basically, you just seem to want to do:



      script:



      #!/bin/bash
      scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


      and launch the script as



      ./script





      share|improve this answer


























        0












        0








        0







        You mess up things while using sudo. Why you use sudo is not clear. Basically, you just seem to want to do:



        script:



        #!/bin/bash
        scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


        and launch the script as



        ./script





        share|improve this answer













        You mess up things while using sudo. Why you use sudo is not clear. Basically, you just seem to want to do:



        script:



        #!/bin/bash
        scp /home/pi/file.txt pi@192.168.178.xx:/home/pi/foo/


        and launch the script as



        ./script






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 2 at 14:57









        Ljm DullaartLjm Dullaart

        75428




        75428






























            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%2f1400943%2frun-ssh-scp-from-bash-script-w-out-password-key-installed%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

            Plaza Victoria

            In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

            How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...