No user exists for uid 502

Just reload your terminal by closing then opening back. Should work after that.


The reason why closing/reopening the terminal solves the issue is because it is an iTerm2 problem: gnachman/iterm2 issue 4147:

An option like the one introduced by commit 316b855 could help:

Turn on Prefs > Advanced > Kill sessions on logout and see if the problem goes away or other bad behavior appears after logging out.

And:

This sounds similar to an old issue we have in Mosh, where user shell sessions can lose permissions to do various things: mobile-shell/mosh issue 249

The root of the problem there has to do with Mach RPC, Unix sessions, and MacOS security contexts; the security context can apparently be lost if parent processes or other processes in the session exit before the user session does. Something like that.

So, typing logout & restarting the session resolves the issue, but does not solve the root cause.

The issue is with sessions that never died. Logging out breaks them, somehow. The session restoration feature keeps sessions alive while the UI is not running (so they can survive crashes or logouts), and this is an undesirable side effect of that.

gnachman/iTerm2 PR 381 should fix things, with iTerm2 v3.3.0beta1, Q1 2019.

Tags:

Github