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!
sudo ssh-copy-id ...
? I'm asking because you're executing your script viasudo
.