PITA!

I spent all morning figuring out how to get the remote execution of Python scripts working.  What a PITA!

It turns out that when you log in through SSH, or in my case SFTP, you get handed a completely PATH environment variable that if you log in locally or through a Virtual Private Network.  That results in the remote system not being able to find commands that it normally as access to via modifications to the user’s .profile or .bashrc files.  When coming in through sftp, none of those modifications are read or applied.

I tried many things and finally got it working by:

  1.  Creating a .ssh directory in each user’s home directory.
  2.  Adding an environment file in each of the new .ssh directories which included the desired PATH definition for that user.
  3. edit the /etc/ssh/sshd_config file so that PermitUserEnvironment is set to yes
  4. restart SSH.
  5. change the ownership and group for any files I want to execute to the logged in user.

Now, I can use pysftp to execute any properly formatted python programs that can be found on the new PATH.

I could have executed the programs by simply using the full path to the program in the sftp.execute command (as long as permissions were set correctly) but I wanted a cleaner solution.

What I have done would not be the most secure setup if there were actually different users but in my situation I am all the users so no big deal.  The potential security issue is because now each user can alter their SSH environment variables.

By the way, connecting up the sensor won’t happen until at least 12/22 because some of the required parts have been delayed.  If UPS decides the roads are too icy for them it may not happen for a few days.

Glad I got it working!  I need a break!

Comments are closed.