Fix unable to log in after logging out with Gnome / GDM3 on Ubuntu

I have encountered a problem for a while: After logging out, I cannot log in to the default Ubuntu (Gnome) session. After some digging, I managed to find a solution to this problem, so this is a solution in case you also encounter this “Cannot log in again after logging out” problem.
The “Cannot log in after logout” problem seems to occur in a Gnome desktop environment using GDM 3 on Xorg, and on a computer using Nvidia graphics using a proprietary driver, although I’m not sure about the last part. Also, problems occur in most cases, but not always.

And it’s not just Ubuntu, as the reports I’ve seen, Fedora Again (it’s marked as fixed, although there are still users looking for a solution), but strangely, it seems to be happening in Wayland instead of Xorg, which is what my computer uses when running this tool. However, this may be another issue, which is why I only mention Ubuntu in the title, but you can try it in any Linux distribution.
It should also be noted that this happens whether it is a single user (there is only one user on the system) or on a system with multiple users, whether you try to log in with the same user or switch to another user.
I encountered this error on Ubuntu 18.04, 18.10 19.04, so it is not new, but it seems to escape the developers. The error may be older, but I didn’t use Gnome before Ubuntu 18.04.
Related to display manager: How to change the default display manager (switch to GDM, LightDM, SDDM or LXDM) in Debian, Ubuntu or Linux Mint looks as if you can’t log in again on Gnome (login in my case it Xorg) because the session did not close / hang properly. The solution was to ensure that the process of the logged out user did not continue by executing the following command killall -9 -u $USER After logging out, for the user who just logged out.
To apply this solution to the problem of “unable to log in after logout”, after selecting logout from the Gnome system menu, you need to run the command I mentioned. You can run the command after the session is complete by adding it to /etc/gdm3/PostSession/Default File-from GDM3 Man page: “After the session is complete, gdm tries to run /etc/gdm3/PostSession/display, Or /etc/gdm3/PostSession/Default“. If you are trying to use this feature on a Linux distribution other than Ubuntu or Debian, please note that the path to the GDM3 PostSession / Default file may be different!
So let’s edit this file using Nano command line text editor:

sudo nano /etc/gdm3/PostSession/Default

the above exit 0 (Last) line, add the following command:

killall -9 -u $USER

Save the file now and exit Nano (To save the file using the Nano command line text editor, press Ctrl + oAnd then Enter; After saving, exit use Ctrl + x).
You should now resolve the issue that the new login does not work after you log out, you can try to log out and log in again (without restarting). I tested this to make sure it works multiple times (and works every time) but only works on Ubuntu 19.04 as I only have one computer to try and it doesn’t seem to be in the virtual machine occur.
If you know of other better solutions, please let me know in the comments section.

Source

Sidebar