How to automate a ssh login?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi there,

I want to connect one linux machine with another linux machine over an
openssh tunnel.

Actually I use Putty on my Windows Workstation and connect to OpenSSH on
the first Linux  Machine. In this session I open the connection to the
second linux machine (the SSH Server).

I want to connect the Linux Machine automatically to the remote Server -
without have to open a shell on the Linux Machine first. Any suggestions?


Kind regards, Thomas

Re: How to automate a ssh login?

Quoted text here. Click to load it

Hi Thomas,

try the following

ssh -t -l <user> first Linux  Machine 'ssh -l <user> second linux

If password authentication is used, you will be required to enter
passwords for two machines.


Re: How to automate a ssh login?

Hi Mike,

thanks for the advice.

Quoted text here. Click to load it

What I wanna do is a "Tunneling Gateway":
Let the first linux machine connnect by using ssh -l -i -g -L [...] the
other linux machine without have to manually initiate the ssh login on
machine 1. The first linux machine should automatically (by using a
shell script? e.g after a reboot) login to the 2nd linux machine and
initiate a port-forwarding with the -g option. Now any other machine on
the network can use the tunnel between linux machine one and linux
machine two without have to initiate an own tunnel.

--LAN 1---|
|         |
|         |--hub--linux 1--router >----< router--linux 2--hub---LAN 2
|                                ssh-tunnel                 |
RDP-Client                          RDP                     |

Maybe you can shed some additional light on me?

Thx so much in advance.
kind regards, Tom

Re: How to automate a ssh login?

Hello Tom,

Quoted text here. Click to load it

Harmonising your explanation with my understanding..Simply there are
two linux machines one in n/w 1 and other in n/w 2. you need  to have
a secure connection from network 1 to 2 (from linux machine 1 to 2).
We can forward the port from machine 2 to 1,with the same option like
-g -R when the ssh connection is made for first time to machine 2.The
local users in n/w 1 can use the forwarded port so that all
connections will be tunneled through the ssh connection.(No seperate
tunnel for each connection).

For running a command (connecting to remote host) without opening a
shell can be done by giving the command in the profile file which will
make the port forwarding to occur. simply insert port forwarding
command can be given in profile file. Try this trick..

also refer

for gateway forwarding


Site Timeline