Newly Created User Cannot Log in to Linux Graphical Desktop: A Step-by-Step Fix
Creating Users in Linux and Enabling Graphical Login
Many Linux beginners encounter a problem after creating a new user: they can switch to the user in a terminal but cannot log in to the graphical desktop. This usually happens because the user is created without a proper home directory or sufficient permissions for the display manager.
Environment Preparation
First, gain root privileges (temporarily) with:
sudo su root
Creating the User Correctly
The command pair:
useradd testname
passwd testname
only creates a basic user entry. To allow graphical login, the user needs a home directory and the correct ownership.
Recommended User Creation Commands
- Create a user with a home directory:
useradd -d /home/testname -m testname
-d /home/testnamespecifies the home directory path.-mensures the directory is created if it does not exist.
- (Optional) Add the user to the
rootgroup immediately:
useradd -d /home/testname -m testname -g root
Verify the User's Groups
groups testname
Completely Remove a User (if needed)
userdel -r testname # -r removes the home directory as well
Setting the Password
passwd testname
Enter the new passwodr twice. Note that the input will not be echoed for security reasons.
Granting sudo Access (Optional but Recommended)
Even if the user is in the root group, they may not have sudo privileges. To enable sudo:
sudo su root
visudo # or vim /etc/sudoers
Look for the line:
root ALL=(ALL:ALL) ALL
Add a new line below it:
testname ALL=(ALL:ALL) ALL
Save and exit (:wq! in vim).
Logging In
After completing these steps, log out of your current session (or restart the display manager) and try logging in with the new user account. You should now see the graphical desktop.
Troubleshooting Tips
- Ensure the home directory exists and is owned by the user:
chown -R testname:testname /home/testname
- If the display manager still refuses login, check
/var/log/lightdm.logor/var/log/gdm3/for specific errors. - Always use
useraddwith-mwhen creating users intended for interactive use.