Loading User LaunchAgent Successfully I have created a plist file to replace an xinetd process that I used successfully in Windows (Cygwin) and Linux to stream an imapd connection from a remote server via ssh on a port on the localhost. 

The plutil command says my configuration is OK. launchctl load path-to-plist runs without errors.  

When I run launchctl list the agent does not display.  When I try to connect to the port on the localhost, I get connection refused.

Here is my plist file:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
            &lt;string&gt;com.my.ssh_tunnel&lt;/string&gt;
        &lt;key&gt;Program&lt;/key&gt;
            &lt;string&gt;/usr/bin/ssh&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
            &lt;array&gt;
                    &lt;string&gt;-F /Users/userx/.ssh/config&lt;/string&gt;
                    &lt;string&gt;dname /usr/sbin/imapd&lt;/string&gt;
            &lt;/array&gt;
        &lt;key&gt;Sockets&lt;/key&gt;
            &lt;dict&gt;
                &lt;key&gt;Listeners&lt;/key&gt;
                &lt;dict&gt;
                    &lt;key&gt;SockServiceName&lt;/key&gt;
                        &lt;string&gt;dname-imapd&lt;/string&gt;
                    &lt;key&gt;SockType&lt;/key&gt;
                        &lt;string&gt;stream&lt;/string&gt;
                    &lt;key&gt;SockProtocol&lt;/key&gt;
                        &lt;string&gt;TCP&lt;/string&gt;
                &lt;/dict&gt;
            &lt;/dict&gt;
        &lt;key&gt;inetdCompatibility&lt;/key&gt;
            &lt;dict&gt;
                &lt;key&gt;Disabled&lt;/key&gt;
                &lt;false/&gt;
                &lt;key&gt;Wait&lt;/key&gt;
                &lt;false/&gt;
            &lt;/dict&gt;
        &lt;key&gt;EnvironmentVariables&lt;/key&gt;
            &lt;dict&gt;
                &lt;key&gt;SSH_AUTH_SOCK&lt;/key&gt;
                    &lt;string&gt;/Users/userx/.ssh-agent.sock&lt;/string&gt;
            &lt;/dict&gt;
    &lt;/dict&gt;
&lt;/plist&gt;


I have added a line to /etc/services for dname-imapd and an unassigned port (49022).  Ultimately I will be using this in conjunction with ssh-agent (to make this work 'passwordless') and Thunderbird to retrieve mail from a very locked down system.

There are essentially two questions here.  One, how do I know my agent is being loaded (and how do I confirm that)?  Two, is my plist actually correct?

Here's my original xinetd config:

service imapssh
{
        disable         = no
        type            = UNLISTED
        port            = 2208
        socket_type     = stream
        protocol        = tcp
        wait            = no
        server          = /usr/bin/ssh
        server_args     = dname /usr/sbin/imapd
        user            = userx
}


Thanks for any help.  This is driving me a little crazy.

This is on an El Capitan Macbook Pro.

Also, I've tried a straight ssh tunnel but that doesn't really work (before anyone suggests it).  Unless someone knows how to make it work like inetd and spawn every time the mail client connects to the port.
OK, addressing your second question first (is my plist actually correct?), plutil (in its default invocation) "lints" (checks) plist files for correctness:

plutil ~/Library/LaunchAgents/local.brew.update.plist


Equivalent to:

plutil -lint ~/Library/LaunchAgents/local.brew.update.plist


Turning to your first question (how do I know my agent is being loaded (and how do I confirm that)?), here's a few things to help check that.

First, I'd recommend adding logging to aid debugging. I log to ~/Library/Logs, so add something like this to my plist:

&lt;key&gt;StandardOutPath&lt;/key&gt;
&lt;string&gt;/Users/userx/Library/Logs/local.brew.update.stdout&lt;/string&gt;
&lt;key&gt;StandardErrorPath&lt;/key&gt;
&lt;string&gt;/Users/userx/Library/Logs/local.brew.update.stderr&lt;/string&gt;


Try re-loading your plist and then check your logs:

less ~/Library/Logs/local.brew.update.stdout
less ~/Library/Logs/local.brew.update.stderr


A few additional observations:

My understanding of your inetdCompatibility is that the agent should start when it's loaded. However, you say that launchctl list doesn't show the agent. Does that change if you try launchctl start com.my.ssh_tunnel after loading the plist? Do the logs show anything new?

I don't entirely understand the relationship between Program and ProgramArguments - could just be me, but I find man launchd.plist's explanation of ProgramArguments hard-going. I'd be inclined to try adding /usr/bin/ssh as a first string in ProgramArguments, and removing the entry for Program. (Then re-load and check the logs. Re-start and check the logs if needed).

Finally, I'm pretty certain that @daniel-Azuelos is correct, and you need to specify your ProgramArguments like this (I've added usr/bin/ssh as mentioned above):

&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/usr/bin/ssh&lt;/string&gt;
    &lt;string&gt;-F&lt;/string&gt;
    &lt;string&gt;/Users/userx/.ssh/config&lt;/string&gt;
    &lt;string&gt;dname&lt;/string&gt;
    &lt;string&gt;/usr/sbin/imapd&lt;/string&gt;
&lt;/array&gt;


My reasoning for this is, the few plists I can find on my system that use (more than one) ProgramArguments use this idiom:

&lt;key&gt;Label&lt;/key&gt;
&lt;string&gt;com.divx.uninstall.preferences&lt;/string&gt;
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;/bin/bash&lt;/string&gt;
    &lt;string&gt;-c&lt;/string&gt;
    &lt;string&gt;if [[ ! -e "/Applications/DivX/DivX Preferences.app" ]] ; then open "/Library/Application Support/DivX/Uninstall DivX for Mac.app"; fi&lt;/string&gt;
&lt;/array&gt;


Note how bash's -c option and the corresponding command_string are in separate arguments.