I'm running autossh on a Mac (Mavericks) from a bash shell script controlled by launchd. Unfortunately, they way I've set this up causes autossh to spawn dozens of instances of both itself and ssh. Eventually the shell seems to grind to a halt and remote connects become impossible. If I killall both autossh and ssh things get back to normal.
This on the host:
Axe:~ mnewman$ ps -A | grep -c -w ssh
41
Axe:~ mnewman$ ps -A | grep -c -w autossh
152
This on the client:
MrMuscle:~ mnewman$ ssh -p19990 mnewman@localhost
Last login: Sat Jul 6 16:19:50 2019 from localhost
-bash: fork: Resource temporarily unavailable
-bash-3.2$
It took me a long time to get this running. So far, I haven't a clue how to figure out what's going on here.
The shell script:
#!/bin/bash
/opt/local/bin/autossh -f -M 0 -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=2 -R 19990:localhost:22 mnewman@korat.myddns.rocks -p 10000
The launchd plist file which is in ~/Library/LaunchAgents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Debug</key>
<false/>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.mgnewman.autossh</string>
<key>ProgramArguments</key>
<array>
<string>/Users/mnewman/bin/autossh.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/mnewman/Desktop/autossh.txt</string>
<key>StandardOutPath</key>
<string>/Users/mnewman/Desktop/autossh.txt</string>
<key>WorkingDirectory</key>
<string>/Users/mnewman/Documents</string>
</dict>
</plist>
What have I done here to spawn so many instances of autossh and ssh?