Permission issue for /run/user/0/jupyter when I execute jupyter notebook

6,231 views
Skip to first unread message

Dij Maha

unread,
Jun 5, 2016, 5:51:42 AM6/5/16
to Project Jupyter
Hi All!
I have a problem in running jupyter notebook:
If I run jupyter notebook without being root I get
PermissionError: [Errno 13] Permission denied: '/run/user/0/jupyter'

The problem occurs when I try to work with Jupyter on a VPS. I tried also with  different distributions: both Ubuntu Server and Arch Linux, and both gives the same error. On the other hand root user doesn't show this issue, but I don't feel really safe to run the notebook server as super user!

I have noticed that on my laptop jupyter works perfectly well since when it starts, it writes on the  `/run/user/1000/` directory that is actually owned by the user itself. So no issues with permissions. (Unfortunately, I cannot simply change the owner of the idrectory /run/user/0/jupyter since it is a temporary dir and is deleted when i close the notebook)
Is it possible to change the default directory? Is there any reason why it choose the /0/ directory that should belong to root? Do the user that run the notebook have to be in a particular group?

Thanks in advance for any suggestion!
D

P.S.  Th jupyter version are both on my server and laptop:
jupyter 4.1.0-4
jupyter-notebook 4.2.0-1
python-ipykernel 4.3.1-1

The Error:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/traitlets/traitlets.py", line 501, in get
    value = obj._trait_values[self.name]
KeyError: 'runtime_dir'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/jupyter-notebook", line 6, in <module>
    main()
  File "/usr/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/lib/python3.5/site-packages/traitlets/config/application.py", line 595, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/usr/lib/python3.5/site-packages/traitlets/config/application.py", line 74, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.5/site-packages/notebook/notebookapp.py", line 1058, in initialize
    self.init_configurables()
  File "/usr/lib/python3.5/site-packages/notebook/notebookapp.py", line 838, in init_configurables
    connection_dir=self.runtime_dir,
  File "/usr/lib/python3.5/site-packages/traitlets/traitlets.py", line 529, in __get__
    return self.get(obj, cls)
  File "/usr/lib/python3.5/site-packages/traitlets/traitlets.py", line 508, in get
    value = self._validate(obj, dynamic_default())
  File "/usr/lib/python3.5/site-packages/jupyter_core/application.py", line 99, in _runtime_dir_default
    ensure_dir_exists(rd, mode=0o700)
  File "/usr/lib/python3.5/site-packages/ipython_genutils/path.py", line 167, in ensure_dir_exists
    os.makedirs(path, mode=mode)
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/run/user/0/jupyter'


Thomas Kluyver

unread,
Jun 5, 2016, 6:14:33 AM6/5/16
to Project Jupyter
On 5 June 2016 at 10:51, Dij Maha <kraz...@gmail.com> wrote:
Is it possible to change the default directory? Is there any reason why it choose the /0/ directory that should belong to root?

It gets the directory from the $XDG_RUNTIME_DIR environment variable. When you log in, that should be set to /run/user/$UID which is owned by the user in question. It sounds like something is erroneously inheriting environment variables from the root user into a context where that's not valid. You can work around it by unsetting $XDG_RUNTIME_DIR before launching the notebook.

Thomas

Dij Maha

unread,
Jun 5, 2016, 6:47:26 AM6/5/16
to Project Jupyter
Thank you very much Thomas, the problem was trivial. Checking the variable you mentioned, I found that the command `su` doesn't change $XDG_RUNTIME_DIR. Therefore, the mistake was logging in as root and then switch user, and this doesn't work. Logging directly as the user, instead,  works perfectly.
Thanks again.
D

Lawrence D’Oliveiro

unread,
Jun 5, 2016, 7:39:43 PM6/5/16
to Project Jupyter
On Sunday, June 5, 2016 at 10:47:26 PM UTC+12, Dij Maha wrote:
Therefore, the mistake was logging in as root and then switch user, and this doesn't work. Logging directly as the user, instead,  works perfectly.

Were you doing “su -”? This should make the shell behave exactly like a login shell <http://linux.die.net/man/1/su>.

Dij Maha

unread,
Jun 5, 2016, 8:01:50 PM6/5/16
to Project Jupyter
Yes, and `su username` doesn't change that particular variable. Googling, I cannot understand if it is a bug or an actual feature of `su`. But, if I understand correctly the man page (that is quite more verbose then the one your link shows, my version is `su from util-linux 2.28`), it seems to be done on purpose:
"For  backward  compatibility,  su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER
       and LOGNAME if the target user is not root).  It is recommended to always use the --login option (instead of its shortcut -) to avoid side effects
       caused by mixing environments."

I have not tested the --login option yet.

Lawrence D’Oliveiro

unread,
Jun 5, 2016, 11:06:11 PM6/5/16
to Project Jupyter
On Monday, June 6, 2016 at 12:01:50 PM UTC+12, Dij Maha wrote:
Yes, and `su username` doesn't change that particular variable.

Ah, fair enough. It’s probably reasonable to say that “behaving exactly like a login shell” requires a bit more work than it used to. :)

shreyash kawalkar

unread,
Jun 24, 2019, 4:56:00 AM6/24/19
to Project Jupyter
export XDG_RUNTIME_DIR=""

Thomas Kluyver

unread,
Jun 24, 2019, 4:34:39 PM6/24/19
to Project Jupyter
Heads up, if you upgrade jupyter_core to 4.5.0, Jupyter should no longer be affected by XDG_RUNTIME_DIR at all:

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/286b23c1-3ea9-41e2-8a26-c9134413b248%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages