My config:
debian 10.9
4.19.0-19-amd64
OpenSSH_7.9p1 Debian-10+deb10u2, OpenSSL 1.1.1d 10 Sep 2019
autossh 1.4g
GNU bash, 5.0.3(1)-release (x86_64-pc-linux-gnu)
I start a service in /etc/systemd/system/myshh.service
ExecStart=/home/user/ssh_run
starts my script ssh_run
THIS ARE ONLY TWO OF A LOT EXAMPLES WITH SSH AND AUTOSSH I TRIED
ssh_run script
#!/bin/bash
ssh -f -NT -o "ServerAliveInteval=30" -o "ServerAliveCountMax=2" \
-R 5555:localhost:443 -l [USER] [IP] -p [PORT] -i [KEY-WITHOUT-PASSWORD]
EXECUTE NEXT COMMAND
or
#!/bin/bash
/usr/bin/autossh -f -NT -o "ExitOnForwardFailure=yes" \
-R 5555:localhost:443 -l [USER] [IP] -p [PORT] -i [KEY-WITHOUT-PASSWORD]
EXECUTE NEXT COMMAND
When i execute the command alone from the shell it works
ssh -f -NT ......
When i execute only the script it works
./ssh_run
When i start the service
/etc/systemd/system/myshh.service
without-f
it works
ALL 3 WITHOUT EXECUTE OF THE NEXT COMMANDS
PROBLEM:
When i start the service /etc/systemd/system/myshh.service
, with the script ./ssh_run
and i use -f
for the background, now the next commands execute but, service exited with status code 0 but no ssh or autossh in ps aux | grep [s]sh
or ps aux | grep [a]utossh
Checked systemctl status myshh.service
i grep
the journalctl
too without an error
the service stops or restart with the same result, i try with and without Restart=30
, Restart=always
or Environment="AUTOSSH_GATETIME=0"
in the service
I read most of the posts of all the stacksites, and try the search engines, no solution found
i try (command)
, exec
, bash -c
.... without result...
Now my problem/question:
How can i execute a ssh/autossh remote port forwarding command inside a bash script in the background, that is start from a service, to execute the next commands.