Calimero Posted January 3, 2021 Share Posted January 3, 2021 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. Quote Link to comment
strike Posted January 3, 2021 Share Posted January 3, 2021 I'm no expert at this at all, but can't you just use screen? Then the tunnel should stay open until you choose to close it or detach from screen. Screen is in nerdpack IIRC. Quote Link to comment
Calimero Posted January 3, 2021 Author Share Posted January 3, 2021 Okay, so you are not an expert? ;). It is working via Terminal, perfect. Now any idea how to put this in a startup-script? Quote Link to comment
strike Posted January 3, 2021 Share Posted January 3, 2021 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. Quote Link to comment
doron Posted January 3, 2021 Share Posted January 3, 2021 A slightly simpler way to get what you want might be: 1. Write a short script that just prints the password ("echo mygoodpassword"). Assume you put it at /root/mypass. 2. In /boot/config/go, add: DISPLAY=: SSH_ASKPASS=/root/mypass setsid ssh -N -R 8000:XX.XX.XX.XX:8000 [email protected] Quote Link to comment
ken-ji Posted January 5, 2021 Share Posted January 5, 2021 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] Quote Link to comment
Calimero Posted January 5, 2021 Author Share Posted January 5, 2021 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. Quote Link to comment
Recommended Posts
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.