Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So I have this school server that I am trying to connect to via nautilus. In terminal it's all easy but I want to be able to open it also in nautilus.

In terminal my way of doing it looks like this:

ssh myUser@my.server.com

Now that I am connected in there, I can do ssh myUser2.my.server2.com inside of that server to connect to server2. I canoot connect to server 2 directly. It has to be done like I do it right now.

So right now I can only get a connection to the first server in nautilus by typing ssh://myUser@my.server.com

But how do I connect to the server2 from there?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

If your first SSH server (my.server.com) supports TCP Port Forwarding, you can forward a port on your local system (localhost) to my.server2.com via my.server.com:

ssh -fNL 2022:my.server2.com:22 myUser@my.server.com

This will forward port 2022 on localhost to port 22 on my.server2.com. Then you can connect directly to the second server:

ssh myUser2@localhost:2022

In Nautilus, you can connect using ssh://myUser2@localhost:2022.


The -fN flags send SSH to the background, and creates a problem in closing it. There are three ways out:

Autoclose

ssh -fNL 2022:my.server2.com:22 myUser@my.server.com sleep 10

Now connect using Nautilus before the sleep command finishes executing (10 seconds). The connection will be kept alive as long as Nautilus is connected. When done, disconnect from Nautilus and the connection will be stopped.

Let the command wait for input

ssh -tL 2022:my.server2.com:22 myUser@my.server.com 'read -p"Press Enter to exit: "'

The read command will wait for input. Press Enter when you're done to close the connection.

Look up the connection process and kill it

pgrep -fa fNL

This will show you all processes which have fNL in the command line (there should only be your SSH connection process). Either kill the PID of the right process if there are more than one, or use pkill if there is only one process: pkill -f fNL This is pretty much the only option for connections that have already been established using -fN.

Run no command, and exit as usual

ssh -L 2022:my.server2.com:22 myUser@my.server.com

This will open a normal shell, from which you can exit as you normally do.

share|improve this answer
    
And after I am done, how do I close this port again? –  Kaspar Sep 4 at 7:57
    
@Kaspar I updated the answer. –  muru Sep 4 at 8:19
    
Thank you for the good answer! This solution works very well for me. –  Kaspar Sep 4 at 8:22

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.