3

Here's a situation:

I do all my work on a Mac.

  1. There's a certain linux server 'server01' that provides access to another linux server 'server02' via a pseudo terminal

    So, to ssh into 'server02', I do this from my mac:

    ssh -t server01 'inline server02'
    
  2. Then it asks me for a password to 'server01'; I enter it and that logs me into 'server02'. Now, I am on the 'server02' terminal.

  3. From 'server02' I can access the mysql database that is sitting on 'server03' using the following mysql command:

    mysql --host=server03 --port=4201 --user=myuser --password=mypass mydb
    
  4. Neither 'server01' nor 'server02' nor my mac have SSH access to 'server03'

Now, I want to access the mysql on 'server03' from my mac directly through some kind of port forwarding. So, if I type the below command on my mac terminal, it should connect me to the mysql database on 'server03':

mysql --host=localhost --port=4201 --user=myuser --password=mypass mydb

Is there a way to do that? Any help is greatly appreciated.

1
  • What does your inline command on server01 do to get to server02? Nov 4, 2015 at 13:06

1 Answer 1

1

If you can ssh to server02 from the server01 you could try

ssh -t -L server02:4201 server01 'ssh -N -L server03:4201 server02' 

it will chain connection

localhost:4201 -> server02:4201 -> server03:4201

just connects locally to port 4201 on the mac

Better use key authentication and ssh-agent to avoid typing passwords.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .