Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have to set up a tunnel between two hosts.

For this i use ssh in this way:

ssh -L MY_LOCAL_PORT:FOREIGN_ADDRESS:FOREIGN_PORT MYUSER@SSH_SERVER

after that, I login into my SSH_SERVER.

How can I avoid this feature?! I have only to set up a tunnel. I don't have to login into my SSH_SERVER...

I've tried the -N option, but it keep my shell busy

share|improve this question
    
SSH -N -L xx:xx:xx user@server & <-- have you tried that before ? –  Lawrence Nov 12 '13 at 7:45
    
Yes, but it doesn't work. When i try to connect with ssh via tunnel, the client tries to connect but it doesn't receive any reply. –  Bau Miao Nov 12 '13 at 8:03
    
Hey, you have right. I've tried on another host and the -N option works. So I've discovered that the problem is on my ssh client (I don't know why, and I will search the reason). Thanks a lot! –  Bau Miao Nov 12 '13 at 9:41

3 Answers 3

up vote 7 down vote accepted

As said in other posts, if you don't want a prompt on the remote host, you must use the -N option of SSH. But this just keeps SSH running without having a prompt, and the shell busy.

You just need to put the SSH'ing as a background task with the & sign :

ssh -N -L 8080:ww.xx.yy.zz:80 user@server &

This will launch the ssh tunnelling in the background. But some messages may appear, especially when you try to connect to a non-listening port (if you server apache is not launched). To avoid these messages to spawn in your shell while doing other stuff, you may redirect STDOUT/STDERR to the big void :

ssh -N -L 8080:ww.xx.yy.zz:80 user@server >/dev/null 2>&1 & 

Have fun with SSH.

share|improve this answer
    
Thanks, your solution is the most graceful! –  Bau Miao Nov 12 '13 at 9:44
2  
You can also use ssh option -f instead of & and io redirection. –  tkrennwa Nov 13 '13 at 13:49

You need to log in to the remote host to set up your tunnel.

However you do not need to run a shell there. man ssh says:

 -N      Do not execute a remote command.  This is useful for just for‐
         warding ports (protocol version 2 only).
share|improve this answer

-f -N is what you are looking for:

ssh -f -N -L MY_LOCAL_PORT:FOREIGN_ADDRESS:FOREIGN_PORT MYUSER@SSH_SERVER
share|improve this answer

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.