1

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 [email protected]

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://[email protected]

But how do I connect to the server2 from there?

1 Answer 1

2

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 [email protected]

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 [email protected] 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 [email protected] '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 [email protected]

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

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

You must log in to answer this question.

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