How to write a script in ssh to a computer from a remote computer?

I often need ssh to the server, but I can not ssh into it directly while I am connected to our VPN. So I have to ssh to another server and ssh into it from there. Is there a way I can write a script and / or shell function for this? I tried this, buit this gave me an error:

% ssh jason@server2 'ssh jason@server1'
jason@server2 password: 
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).

(and of course the username and server name have been changed)

+3
source share
4 answers

A combination of SSH connections can help you. Assuming the following layout: Client → Middman → Purpose

On the client:

ssh user@Middleman -L 1337:Destination:22

This will allow you to directly SSH to Destination from Client in another session:

On the client:

ssh user@localhost -p 1337

, ssh user @Destination. stdin , .

+3

. , (, , ssh-, ).

+4

, , , ssh . , . , , ssh, ssh . . , , .

+1
source

It looks like you want to configure public key authentication between the middle machine and the end machines.

Here are some decent guides to get you started. Good luck.

http://hkn.eecs.berkeley.edu/~dhsu/ssh_public_key_howto.html

http://pkeck.myweb.uga.edu/ssh/

+1
source

Source: https://habr.com/ru/post/1717258/


All Articles