'Replicating ssh behavior with jupyternotebook spawn

OBS1: this question is duplicated here as suggested by Wayne in the comments, but still with no answer.

I have a remote machine running ubuntu where i am configuring a jupyterhub notebooks server. The server is already up and running, however, i noticed that it only works well with users that have previously logged in the machine via ssh. For users that have never logged in the machine via ssh before, the server spawns a login screen but after the login comes the following image:

enter image description here

It displayed a different directory path before (i mean different than /user/john.snow), but i configured the jupyterhub spawner class to make the directory by adding the lines:

if os.path.exists('mkdir /home/FOLDER/' + env['JUPYTERHUB_USER'])!=True:
    os.system('mkdir /home/FOLDER/' + env['JUPYTERHUB_USER'])

(i append the complete spawner code at the end of the question, if thats useful)

Since i dont intend to need to test every single directory that jupyter notebook looks for, my desire is to find the ssh configuration files in the computer and mimic what ssh does for that particular user with the spawner. Is it possible? I tried looking at /etc/ssh/ssh_config and similar but almost all of the file is commented and the syntax is mysterious.

Thanks for any suggestions.

OBS: full spawner code:

import os, getpass
import yaml
from jupyterhub.spawner import Spawner, LocalProcessSpawner

class spawner(LocalProcessSpawner):

    def start(self):
        # get environment variables,
        # several of which are required for configuring the single-user server
        env = self.get_env()
        ret = super(spawner, self).start()
        if os.path.exists('mkdir /home/FOLDER/' + env['JUPYTERHUB_USER'])!=True:
            os.system('mkdir /home/FOLDER/' + env['JUPYTERHUB_USER'])
        os.system('mkdir /home/FOLDER/' + env['JUPYTERHUB_USER'] + '/notebooks')
        os.system('cp -r /usr/local/scripts/notebooks/* /home/FOLDER/' + env['JUPYTERHUB_USER'] + '/notebooks/')
        os.system('chmod -R 777 /home/FOLDER/' + env['JUPYTERHUB_USER'] + '/notebooks/')



        return ret


Solution 1:[1]

I found a solution to the problem. Since the spawner code was trying to access folders created by an ssh into the machine, the lines

if os.path.exists('mkdir /home/FOLDER/' + env['JUPYTERHUB_USER'])!=True:
        os.system('mkdir /home/FOLDER/' + env['JUPYTERHUB_USER'])

were trying to create this folder if it didnt exist. However, there were other mysterious configurations that ssh generated and i couldnt figure out to replicate. Instead, i found out that ssh configuration files are at /etc/skel, so i removed these two lines from the spawner and, instead, added:

os.system('su ' + env['JUPYTERHUB_USER'])
        os.system('source /etc/skel/.bashrc')
        os.system('source /etc/skel/.profile')
        os.system('exit')

the 'su env["JUPYTERHUB_USER"]' and 'exit' lines being there because the spawner seems to be executed as root. It solved for new users, but old users who had already spawned the red bar were still dealing with it. It seems that deleting their home folders in the machine solved the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marco Montevechi Filho