How to Fix "Failed to Reset Lastlog Entry" Error When Adding WordPress/Python or any similar Site in CloudPanel

How to Fix “Failed to Reset Lastlog Entry” Error When Adding WordPress/Python or any similar Site in CloudPanel

The Problem

When trying to add a new WordPress site in CloudPanel, you might encounter this frustrating error message:

An error has occurred, error message: Command " : /usr/bin/sudo /usr/sbin/useradd -p $(/usr/bin/openssl passwd -6 'Rh6puufsdfasduibdo3ALMh2DYH') -m 'techc' -k '/home/clp/htdocs/app/files/resources/etc/skel/site-user' -s '/bin/bash' -d '/home/techc' " failed, error message: useradd: failed to reset the lastlog entry of UID 1013: No such file or directory useradd: failed to reset the lastlog entry of UID 1013: No such file or directory



This error occurs due to file permission issues with system log files, but don’t worry – it’s easy to fix!

The Solution

Follow these steps to resolve the issue:

  1. Log in to your server as the root user
  2. Copy and paste these commands one by one:
chattr -i /var/log/lastlog
chattr -i /var/log/utmp
chattr -i /var/log/wtmp
chmod -R 755 /var/log/
chattr -i /var/log/utmp

These commands will:

  • Remove the immutable attribute from system log files
  • Set the correct permissions for the log directory
  • Allow CloudPanel to properly create new user accounts

After running these commands, try adding your WordPress site again – it should work without any errors!

Why This Happens

This issue isn’t actually a bug in CloudPanel, but rather a system-level permission problem that prevents CloudPanel from properly creating new user accounts. The commands above fix this by adjusting the file permissions and attributes of crucial system log files.

Additional Tips

  • Make sure you run these commands as the root user
  • Double-check that your domain is properly configured in your DNS settings
  • If you’re still experiencing issues, check CloudPanel’s error logs for additional information

Remember to always backup your system before making any system-level changes!

If the above steps dont work you can try

Initial Problem:

  • The system log files (lastlog, utmp, and wtmp) appear to be corrupted or have incorrect permissions
  • These files are used to track user login history and system activity

Step-by-Step Solution:

  1. Initial Check:

    df -T /var/log/lastlog
    

    This shows the file system type and space information for the lastlog file.

  2. Important Note:

    • lastlog is a virtual file, which means you cannot use chattr (change attribute) commands on it
    • To verify the current attributes, we use:
    lsattr /var/log/lastlog /var/log/utmp /var/log/wtmp
    


    if you get the above message then file system is corrupt.

  3. Fix Corrupted Files:

    # Backup existing files
    mv /var/log/lastlog /var/log/lastlog.bak
    mv /var/log/utmp /var/log/utmp.bak
    mv /var/log/wtmp /var/log/wtmp.bak
    
    # Create new files
    touch /var/log/lastlog
    touch /var/log/utmp /var/log/wtmp
    
    # Set correct permissions
    chmod 644 /var/log/lastlog  # rw-r--r--
    chmod 664 /var/log/utmp /var/log/wtmp  # rw-rw-r--
    
    # Set correct ownership
    chown root:root /var/log/lastlog
    chown root:utmp /var/log/utmp /var/log/wtmp
    
  4. Restart Services:

    systemctl restart rsyslog
    systemctl restart systemd-logind
    

    This ensures the logging services pick up the new files correctly.

File Purposes:

  • lastlog: Records the last login time for each user
  • utmp: Tracks currently logged-in users
  • wtmp: Maintains history of all logins and logouts

These steps will create fresh log files with the correct permissions and ownership, resolving any corruption issues while maintaining proper system logging functionality.