OptionsApp on Linux, part 4: Tailscale, troubleshooting and security
This is part 4 of 4 of the guide OptionsApp on Linux. Step 10 is optional: afterwards, no port is reachable from the internet any more, and you connect via Tailscale only. Troubleshooting and security follow below. The guide is meant for users who already work with Linux. Placeholders such as IP-ADDRESS, USERNAME and TAILSCALE-IP are listed in the overview.
Step 10 (optional): Access via Tailscale only
After step 3, ports 22 and 3389 are reachable from the internet, at best for your own IP address only. If your IP address changes, you cannot reach the server until you adjust the rules, and your old address may be assigned to someone else.
Tailscale connects your PC and your server through a private, encrypted network. The server sets up the connection outwards itself, so no port has to be open for it. At the end of this step, no port is reachable from the internet any more, and you connect via Tailscale only, whatever IP address you currently have.
Tailscale is a service of another provider, for which you need your own account. You find its terms and prices on tailscale.com.
Set up Tailscale on Windows
Download Tailscale for Windows from tailscale.com/download, install it and log in. This creates your Tailscale account.
Set up Tailscale on the server
Open a terminal in the Remote Desktop session as before, or connect via SSH.
The first command downloads the Tailscale installation script and runs it. It installs Tailscale and sets up the service tailscaled so that it starts automatically every time the server boots:
curl -fsSL https://tailscale.com/install.sh | shThe next command registers the server with Tailscale. It prints a link ("To authenticate, visit: ..."). Open the link in the browser on your PC and log in with the same Tailscale account as on Windows:
sudo tailscale upYou only log in once; the login is kept after a restart. Then display the Tailscale address of the server:
tailscale ip -4The output starts with 100.. This is the TAILSCALE-IP that you use from now on instead of the public IP address.
Turn off automatic logout
Tailscale requires every device to log in again after 180 days. For a server that runs around the clock, you would then lose access. Open the device list at login.tailscale.com/admin/machines, click the "..." menu of the server and choose "Disable key expiry". The server is listed there under its host name, in the screenshot ubuntu.
Connect via Tailscale and test
Connect via Remote Desktop to TAILSCALE-IP instead of the public IP address. Test SSH as well:
ssh -i $HOME\.ssh\optionsapp_vps USERNAME@TAILSCALE-IPIf you saved the password in Windows in step 6, the entry only applies to the old address. Create it again for the Tailscale address and delete the old one:
cmdkey /generic:TERMSRV/TAILSCALE-IP /user:USERNAME /pass
cmdkey /delete:TERMSRV/IP-ADDRESSIf you created the SSH configuration in step 5, open it with notepad $HOME\.ssh\config and replace the IP address after HostName with TAILSCALE-IP.
Only continue once Remote Desktop and SSH work via TAILSCALE-IP. The following commands close access via the public IP address.
Set up the firewall on the server
The Ubuntu firewall ufw closes the ports directly on the server, for IPv4 and for IPv6. This matters because many servers have a public IPv6 address in addition to the IPv4 address, and depending on their settings, firewall rules at the provider only apply to one of the two.
Run the commands in the terminal of a Remote Desktop or SSH session that you opened via TAILSCALE-IP, not via the public IP address. For each command, first read what it does.
The first command resets the firewall to its installation defaults and turns it off. Any rules that already exist are deleted; ufw makes a backup copy first. From here on, you build the rules up again. Answer the question "Proceed with operation (y|n)?" with y:
sudo ufw resetThe next command makes the firewall reject every incoming connection that none of the following rules explicitly allows:
sudo ufw default deny incomingThis command still allows the server to make all outgoing connections. Ubuntu updates, the connection of TWS to Interactive Brokers, OptionsApp and Tailscale itself need them:
sudo ufw default allow outgoingThis command allows everything that arrives via Tailscale, that is, via the network interface tailscale0. Only devices logged in to your Tailscale account arrive there. This makes Remote Desktop and SSH work via TAILSCALE-IP:
sudo ufw allow in on tailscale0This command allows SSH via IPv4 on the server. It is your emergency exit in case Tailscale is ever unreachable. The port is still not open, because the firewall at your provider blocks it (next section). You only get through if you temporarily add a rule for port 22 there. If your provider has no firewall of its own, leave this command out; SSH then works via Tailscale only:
sudo ufw allow proto tcp from 0.0.0.0/0 to any port 22This command turns the firewall on. From now on, it also starts automatically after every restart. Answer the question "Command may disrupt existing ssh connections. Proceed with operation (y|n)?" with y. Your session via Tailscale stays connected:
sudo ufw enableFinally, display the active rules:
sudo ufw status verboseThe output must contain Status: active and Default: deny (incoming), allow (outgoing). Below that, there is a rule Anywhere on tailscale0 (once for IPv4, once with "(v6)") and a rule 22/tcp without "(v6)". There must be no rule for port 3389.
Adjust the firewall at your provider
In your provider's customer portal, delete the rules for ports 22 and 3389 from step 3, so that no rule for incoming connections is left. Tailscale does not need a rule there.
The firewall must stay switched on. At STRATO, its state is shown at the top right of the firewall view. If it says "Inaktiv" (inactive), click "Aktivieren" (activate); otherwise no rule applies and all ports are reachable from the internet.
Check
Check in PowerShell that Remote Desktop is blocked via the public IP address. The command takes about 20 seconds and must print TcpTestSucceeded : False:
Test-NetConnection IP-ADDRESS -Port 3389Via Tailscale, the same test must print TcpTestSucceeded : True:
Test-NetConnection TAILSCALE-IP -Port 3389With -Port 22, you check SSH the same way.
Finally, restart the server once and connect again via TAILSCALE-IP. This shows that Tailscale and the firewall start by themselves. A restart closes OptionsApp and TWS, so do it when no trades are running:
sudo rebootEmergency exit if Tailscale is unreachable
First check on your PC that Tailscale is running and logged in (icon in the notification area of the taskbar). OptionsApp and TWS keep running on the server even if Tailscale fails; only your access is missing. If the problem is on the server, this is how you get back in:
- In your provider's customer portal, add a firewall rule: protocol TCP, IPv4, port 22, with your current IP address as the source.
- Connect in PowerShell via the public IP address:
ssh -i $HOME\.ssh\optionsapp_vps USERNAME@IP-ADDRESS. - Restart Tailscale on the server:
sudo systemctl restart tailscaled. Then check withtailscale statusthat the server is connected again. If the command shows "Logged out", register the server again withsudo tailscale up. - Delete the rule from item 1 again.
If SSH does not work either, many providers offer a console in the customer portal that works without a network connection to the server (at STRATO: "VNC Konsole"). You log in there as root with the password that you set when you installed the operating system.
Every device in your Tailscale account can reach the server. Remove devices you no longer use in the Tailscale device list.
Troubleshooting
| Message or problem | Cause | Solution |
|---|---|---|
| Enter passphrase for key ... and you do not know the passphrase | The passphrase is not stored anywhere. | Create a new key (step 1) and add it on the server, see below. |
| Permission denied (publickey) | Your key is not set up for this user, or -i points to a different key file. | Run step 5. Check on the server: cat ~/.ssh/authorized_keys must contain the line from your .pub file. |
| WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! | The server was reinstalled and received a new server key in the process. | Only after a reinstallation: run ssh-keygen -R IP-ADDRESS in PowerShell, then connect again. Without a reinstallation, do not connect and ask your provider. |
| Could not get lock /var/lib/dpkg/lock-frontend | Shortly after the first start, Ubuntu installs updates automatically. | Wait a few minutes and repeat the command. You can simply restart the setup script. |
| No terminal for the prompts from the setup script | The script cannot ask for the user name and password. | Use option A from step 4. |
| Remote Desktop does not connect | Port 3389 is blocked, or xrdp is not running. | Check the firewall (step 3). Via SSH: systemctl status xrdp must show "active (running)". |
| Remote Desktop via TAILSCALE-IP does not connect | Tailscale is not running or logged out on the PC or the server. | Start Tailscale on the PC and log in. If that does not help: emergency exit from step 10. |
| Login window appears although the password is saved | The address after TERMSRV/ does not match the one under "Computer", or the saved password is out of date. | In PowerShell, cmdkey /list:TERMSRV/* shows the saved entries. Create the entry again with the correct address and the current password (step 6, connect without the login window). |
| Black screen or immediate disconnect after login | The existing session is stuck. | Via SSH as root: loginctl terminate-user USERNAME, then connect again. This closes all programs of this user, including OptionsApp and TWS. |
| Links from OptionsApp do not open a browser ("Failed to execute default Web Browser") | The session runs without the setting from the setup script. | In the terminal, echo $XAUTHORITY must print the path /home/USERNAME/.Xauthority. If the output is empty: run the setup script again, log out and log in again. |
| Unable to locate package with apt install | The ./ before the file name is missing. | sudo apt install ./optionsapp_VERSION_amd64.deb |
| Windows drives do not appear under ~/thinclient_drives | The drive redirection of xrdp does not work on every system. | Transfer files with scp (step 7, method A). |
Adding a new key later
If you can still log in via Remote Desktop, you can add a new public key yourself. Display it in PowerShell (Get-Content $HOME\.ssh\optionsapp_vps.pub), copy the line and run this in the terminal of the Remote Desktop session:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "PASTE-THE-COPIED-LINE-HERE" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keysSecurity
- Choose a strong password for your user, because port 3389 is reachable from the internet.
- Never share the private key (the file without
.pub). - If possible, open ports 22 and 3389 in the firewall for your own IP address only.
- With step 10 (access via Tailscale only), no port is open to the internet at all.
- If you saved the password in Windows (step 6), lock your PC when you leave it.
Advanced: tunnel Remote Desktop through SSH
This way, port 3389 can stay completely closed in the firewall, and only port 22 has to be open. In PowerShell, open the tunnel and leave the window open:
ssh -i $HOME\.ssh\optionsapp_vps -N -L 13389:localhost:3389 USERNAME@IP-ADDRESSThen enter localhost:13389 as the computer in Remote Desktop Connection.
Back to part 3: install OptionsApp and TWS or IB Gateway. All parts at a glance: OptionsApp on Linux.