I have three systems , a client that only install ssh client and server_1 and server_2 . im using ssh public authentication and i can ssh from client to both server_1 and server_2. i saved same pub key for server 1 and and now i want to ssh from server 1 to server 2 using agent forwarding and i want my private key stay only on client please help me ASAP how can i do this scenario ? i use this link but dont know how to do it .
An Illustrated Guide to SSH Agent Forwarding: Public Key Access with Agent Forwarding
03 Answers
First you have to invoke ssh-agent on your client to make it remember your key
ssh-agent -t 3600 ~/.ssh/private_key_rsa(assuming that your key is stored in ~/.ssh/private_key_rsa, you can also leave out the -t 3600 if you want infinite lifetime)
then you simply ssh into one of your servers using the -A option
ssh -A server1from there you will then be able to ssh into server2
ssh server2If you do not want to specify the -A option everytime you can add the following to your ~/.ssh/config (on the client and optionally both servers)
Host server1 ForwardAgent yes
Host server2 ForwardAgent yesThis works for any number of servers. To keep the ~/.ssh/config short you can introduce wildcards e.g.
Host server? ForwardAgent yes 3 Forward server host to localhost :
ssh -L localhost:22:localhost:22 user@hostor
ssh -N -f -L serverhost:22:localhost:22 user@server1After reading your question again.
You want to ssh into server1 :
ssh user@server1Then you want to ssh into server2:
Into new terminal from client do:
ssh user@server1
ssh user@server2Then you have 2 connections:
- client to server 1
- client to server 1 ==> server 2
If you want to have:
- client to server 1
- client to server 2 (With same key.)
Just do following command.
On client:
Use tmux or open 2 terminals
ssh user@server1In new terminal:
ssh user@server2 14 Simple answer is to add flag -A like this:
ssh -A [user]@[hostname]