Transfering files directly between two servers: setting up ssh keys
Search words: upload ssh
Two servers with ssh keys instead of password logins won't let you copy a file directly between servers until you set this up.
(These instructions may be incomplete.)
On the new server:
cp /home/dan/.ssh/id_rsa.pub /home/dan/
If there is no file like that or .pub, make it first: ssh-keygen -t dsa
From your computer:
Bring the id_rsa.pub (or id_dsa.pub, if you created it per above, the examples here mix the two to make sure you don't just copy and paste. Typing builds character)-- bring the file down to the local computer, from the new server, using scp:
scp -r [email protected]:/home/dan/id_dsa.pub id_dsa.pub
The file is moved from .ssh because my user, ben, can't sudo into user dan's ssh folder, in any way that I know of, from a remote computer.
For root, and in this case root's own public key, it could be simply:
scp [email protected]:/root/.ssh/id_dsa.pub id_dsa.pub
Now scp that file up to the old, or main, server:
Ebony:~/Documents/Agaric Design Collective/Us/Dan ben$ scp id_rsa.pub [email protected]:/home/ben/id_rsa.pub
On the old server:
cd ~
su root
mv id_rsa.pub /home/dan/
cat /home/dan/id_rsa.pub >> /home/dan/.ssh/authorized_keys
Now, from the new server, you can do commands like:
scp [email protected]:/home/ben/wsf_copy.sql wsf_copy.sql
Another maybe cleaner example
On local computer:
scp Dan/ubuntumini/id_dsa.pub [email protected]:~
id_dsa.pub 100% 599 0.6KB/s 00:00
On the server:
ben@server:~$ su root
Password:
server:/home/ben# cat id_dsa.pub >> /home/dan/.ssh/authorized_keys
cp /home/dan/.ssh/id_rsa.pub /home/dan/
If there is no file like that or .pub, make it first: ssh-keygen -t dsa
From your computer:
Bring the id_rsa.pub (or id_dsa.pub, if you created it per above, the examples here mix the two to make sure you don't just copy and paste. Typing builds character)-- bring the file down to the local computer, from the new server, using scp:
scp -r [email protected]:/home/dan/id_dsa.pub id_dsa.pub
scp [email protected]:/root/.ssh/id_dsa.pub id_dsa.pub
Ebony:~/Documents/Agaric Design Collective/Us/Dan ben$ scp id_rsa.pub [email protected]:/home/ben/id_rsa.pub
On the old server:
cd ~
su root
mv id_rsa.pub /home/dan/
cat /home/dan/id_rsa.pub >> /home/dan/.ssh/authorized_keys
Now, from the new server, you can do commands like:
scp [email protected]:/home/ben/wsf_copy.sql wsf_copy.sql
Another maybe cleaner example
On local computer:scp Dan/ubuntumini/id_dsa.pub [email protected]:~
id_dsa.pub 100% 599 0.6KB/s 00:00
On the server:
ben@server:~$ su root
Password:
server:/home/ben# cat id_dsa.pub >> /home/dan/.ssh/authorized_keys


Comments
I had so much trouble
I had so much trouble finding this post again, here's a mess of key words:
ssh key access
server key access
public key
ssh server access
cat pub
some more... getting two servers to communicate agaric
Did it the vice versa way for convenience of sending from server
Server 1 (which does not yet have access to server 2):
ssh-keygen -t dsaServer 2 (which already had access to server 1, otherwise you'd need to do the up-and-down steps above):
sudo scp -r [email protected]:~/.ssh/id_dsa.pub id_dsa.pubcat id_dsa.pub >> .ssh/authorized_keys
And that's it! (This gives access only for user ben.)
If you still have password login
there is a shortcut, courtesy Stefan.
First step only if no public key for your user on that server already (that is, if it asks you to overwrite a file, say no, unless you know the file is no good, blacklisted by a security update for instance).
If the ssh-copy-id step doesn't work, run
exec ssh-agent bashfirst.From the server you are on, with dest.example.org being the new server or otherwise destination server you are trying to access with passkeys:
ssh-keygenssh-copy-id dest.example.org
Bonus! Watch success in action (or analyze failure) with (on the destination server, generally):
sudo tail /var/log/auth.logPost new comment