I am trying to open a socket in python and have it listen for connections on a certain port. The python script works if I log in via SSH and run it manually. However, I'm trying to get this to run automatically on boot (ideally), or if necessary, I can login using an automated script and run the command using paramiko. Neither option seems to be working for me though, the socket never starts listening.

Initially I tried running the script on startup by creating an rc.local file, and having it run the python script. This works for one other script that sends an outgoing connection to a remote server (also using a python socket), but does not work to listen on a port.

If I try to run the command with paramiko from the remote connecting machine, I get errors about environment variables not being set.

Any ideas on what to try? What I'm doing is something that definitely works in Raspbian.