SSH - Reverse Tunnel Problem


Recommended Posts

New to unraid.

 

I have a command like this: 

ssh -R 8000:XX.XX.XX.XX:8000 [email protected]

If i write this command in the Terminal window in unraid it works, obviously.

But if i close this Terminal window in unraid, this tunnel is closed, obviously.

 

Is there any tool to fire this event...

... in the background

... at a start of unraid system?

 

I came across the User-Scripts Plugin and tried to fix this problem with script like that

#!/usr/bin/expect -f

spawn ssh -N -R 8000:XX.XX.XX.XX:8000 [email protected] &
expect "Password:*"
send "XXXXX\r"

expect eof
exit

And it works, but not "really" in the background. The tunnel cannot be open...

 

Maybe i just forgot something in the script or just can use another Tool... I don't know.

Link to comment

Actually I have no idea, I'm no good at programing. But maybe this works:

 

#!/bin/bash
screen -d -m ssh -N -R 8000:XX.XX.XX.XX:8000 [email protected] &
expect "Password:*"
send "XXXXX\r"
expect eof
exit

According to the screen manual the -d -m option:

Quote

-d -m
Start screen in detached mode. This creates a new session but doesn’t attach to it. This is useful for system startup scripts.

 And just set user script to run at array start? If it works then you need some more commands to kill it when you want. 

Link to comment

You actually want to be using private keys and the builtin background capability of SSH

I'll assume you known how to generate private+public key pairs else see this for a primer

When you are sure the keys are working correctly (generate them without passphrase encryption) and can ssh to the other server without being prompted for anything, Try the ssh command below (which will be exact command you stick into your script or go file)

#!/bin/bash
ssh -f -i path/to/ssh/private.key -R 8000:xxx.xxx.xxx.xxx:8000 [email protected]

 

Link to comment

Ken-ji, you are totally right. I will do this change this of course. First, i struggled with these two problemes:

1. How to start a script, in the background, to open a tunnel (forever).

2. Go-Script or User-Scripts.

 

For for now, i think with the go file it working. 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.