fixing Ubuntu login issues, including login loops, .Xauthority problems, and home directory permission issues.
A comprehensive solution for fixing common Ubuntu login issues, including login loops, .Xauthority problems, and home directory permission issues.
π¨ Common Ubuntu Login Issues
This script addresses the following common login problems:
- Login Loop - You enter your password correctly, but the screen goes black and returns to the login screen
- .Xauthority Issues - Corrupted X authority files preventing GUI login
- Home Directory Permission Problems - Incorrect ownership or permissions on home directory
- Temporary Profile - System creating temporary profiles due to file access issues
- Display Manager Problems - Issues with GDM3, LightDM, or SDDM configuration
π Prerequisites
- Ubuntu/Debian-based Linux distribution
- Root/sudo access
- Access to TTY console (Ctrl+Alt+F3)
π Quick Start
Direct Run From GitHub Repo
Run the script directly without downloading a local file:
curl -fsSL https://raw.githubusercontent.com/rajibdpi/ubuntu-login/main/fix.sh | sudo bash
From the Login Screen
If you're stuck at the login screen:
- Press
Ctrl+Alt+F3to access a text console - Login with your username and password
- Run the fix script directly from GitHub:
# Run the script (will auto-detect your username)
curl -fsSL https://raw.githubusercontent.com/rajibdpi/ubuntu-login/main/fix.sh | sudo bash
Manual Usage
If auto-detection picks the wrong user, set the target explicitly:
curl -fsSL https://raw.githubusercontent.com/rajibdpi/ubuntu-login/main/fix.sh | sudo bash -s -- --user username
Replace username with the actual username that has login issues.
Optional: Reset GNOME User Config
If login issues are caused by broken GNOME user settings/extensions, run with:
curl -fsSL https://raw.githubusercontent.com/rajibdpi/ubuntu-login/main/fix.sh | sudo bash -s -- --reset-gnome
π§ What the Script Does
The script performs the following fixes:
1. Auto-Detects Target User
- Uses
SUDO_USERfirst - Falls back to
logname - Final fallback is first regular local user (UID >= 1000)
2. Fixes .Xauthority and .ICEauthority
- Backs up existing files with timestamp suffix
- Removes broken authority files that can cause login loops
3. Repairs Ownership and PATH in User Shell Files
- Runs ownership repair on the user home directory
- Backs up
.profile,.bashrc,.bash_profile,.zprofile,.zshrc - Appends a safe PATH export to
.profileand.bashrcif missing
4. Repairs Core Desktop/Login Packages
- Runs
apt-get update - Runs
apt-get -f install -yanddpkg --configure -a - Reinstalls
gdm3,gnome-shell,ubuntu-session, andxorg - Enables
gdm3
5. Optional GNOME Profile Reset
- With
--reset-gnome, backs up and resets:.config.local/share.cache
6. Rewrites Global PATH in /etc/environment
- Backs up existing
/etc/environment - Rewrites it to:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
β οΈ Safety Features
- Creates backups of all files before modification
- Validates target user and home directory before making changes
- Requires root privileges for safety
- Uses strict Bash mode (
set -euo pipefail)
π Troubleshooting
If the script doesn't resolve your issue, try these additional steps:
1. Check System Logs
journalctl -xe
2. Reconfigure Display Manager
# For GDM3
sudo dpkg-reconfigure gdm3
# For LightDM
sudo dpkg-reconfigure lightdm
3. Check for Disk Space Issues
df -h
If your disk is full, clean up space:
# Clean apt cache
sudo apt-get clean
# Remove old kernels
sudo apt-get autoremove
4. Verify Home Directory Permissions
ls -la /home/username
The home directory should be owned by the user with 755 permissions.
5. Check Authentication Logs
sudo tail -f /var/log/auth.log
6. Try Creating a New User
As a test, create a new user to see if the issue is system-wide:
sudo adduser testuser
π Known Limitations
- The script must be run from a TTY console or SSH session, not from the GUI
- Requires sudo/root access
- Reinstalling packages requires network access to apt repositories
- The script rewrites
/etc/environmentPATH to a known-safe value
π‘ Prevention Tips
To avoid login issues in the future:
- Regular Backups - Keep backups of your home directory
- Monitor Disk Space - Keep at least 10% free space
-
Careful with Permissions - Avoid using
sudowith GUI applications - Update Regularly - Keep your system updated
- Graceful Shutdowns - Always shutdown properly to avoid file corruption
π€ Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
π License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
π Acknowledgments
This script was created to help users resolve common Ubuntu login issues based on community solutions and best practices.
β‘ Emergency Recovery
If you cannot access TTY console:
- Boot from Ubuntu Live USB
- Mount your main partition
- Chroot into your system
- Run the fix script
- Reboot
Example:
sudo mount /dev/sdaX /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
curl -fsSL https://raw.githubusercontent.com/rajibdpi/ubuntu-login/main/fix.sh | bash
exit
sudo reboot
Replace /dev/sdaX with your actual root partition.
Top comments (0)