Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to connect to one of my internal computers (private ip) using SSH over the internet. The SSH port of that computer is not exposed so I first create a tunnel via a public resource (public ip).

ssh <public ip> -p 2022 -l root -L 127.1.1.1:2222:<private ip>:22

After that, I can create the SSH connection like this :

ssh username@127.1.1.1 -p 2222

Is it possible to execute this with a single command ?

share|improve this question
    
This question is similar to this one superuser.com/questions/465423/… –  JoBo Aug 23 '13 at 19:34

1 Answer 1

You could always just run the commands, one after the other:

ssh root@<public ip> -p 2022 -L 127.1.1.1:2222:<private ip>:22 && 
    ssh username@127.1.1.1 -p 2222

To spare yourself a lot of unnecessary typing, use bash aliases. Add a line like this to your $HOME/.bashrc:

alias ssh_tunnel='ssh <public ip> -p 2022 -l root -L 127.1.1.1:2222:<private ip>:22 && ssh username@127.1.1.1 -p 2222'

Now, open a new terminal and you can launch the tunnel and connect by running

ssh_tunnel
share|improve this answer
    
Just found out that this single command works : ssh -A -t root@<public ip> ssh -A -t <private ip> . No need to do it in 2 steps apparently. –  ddewaele Apr 1 '13 at 23:37
    
@ddewaele ah, makes sense, you give ssh as the command that ssh should run. Fair enough. I still recommend an alias though, saves a lot of typing. –  terdon Apr 2 '13 at 1:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.