LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   SSH to second server using SSH agent (https://www.linuxquestions.org/questions/linux-newbie-8/ssh-to-second-server-using-ssh-agent-4175713203/)

linux_789 06-09-2022 10:28 AM

SSH to second server using SSH agent
 
I need to get to my second server (SVR2) using key pairs instead of password (Site policy). I use Putty on my windows laptop to SSH to the first server (SVR1) with no problem. The second server is remote and I cannot doing anything without successfully SSH to it. My user ID is user1 on both SVR1 and SVR2

On the putty session I specified "Allow agent forwarding". To SSH to SVR2, on SVR1, I entered
$ssh -v -A user1@SVR2.com, the output shows
(I cut off some output to reduce space, let me know if I cut off too much)
debug1: identity file /home/user1/.ssh/id_rsa type -1
:
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs.............
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user1/.ssh/id_rsa
debug1: Trying private key: /home/user1/.ssh/id_dsa
debug1: Trying private key: /home/user1/.ssh/id_ecdsa
debug1: Trying private key: /home/user1/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

On SVR1 /home/user1/.ssh directory only has
-rw------- 1 ec2-user ec2-user 401 Jun 6 20:11 authorized_keys
-rw-r--r-- 1 ec2-user ec2-user 376 Jun 7 21:50 known_hosts

]$ eval $(ssh-agent)
Agent pid 2904
This shows that the SSH agent is running.

Please correct me if I am wrong. The last few lines of debug output seems that it is looking for private key in the directory. But I think one of the the purpose of using the SSH agent is not having to put my private key in the intermediate server.
Can you help me to understand what is leading to the "Permission denied (publickey)" error?

I think SVR2 has to have my public key. This is where I am also confused. How can I get my public key to SVR2 if I cannot SSH to it ?

rkelsen 06-09-2022 04:20 PM

SSH to second server using SSH agent
 
man ssh-copy-id


All times are GMT -5. The time now is 05:39 PM.