The common scenario:
You installed Ubuntu Server and named your initial user something stupid. Now you need to change it. This is the only user with sudo permissions and if you try to change it while logged in as it, it won’t work. Here is the work around…
1. Create a TEMP user.
2. Add TEMP user to sudo group
3. Use TEMP user to change first user (we will called first user ADMIN in this example) login name
4. Delete TEMP user
First, login as your current sudo user (in this example, “admin”) and elevate privileges, then create new user and set password…
useradd -G sudo temp
shutdown now -r
Logout and log back in as the new “temp” user. Elevate privileges and change username of first account (ADMIN).
usermod -l localadmin admin
Log back in as the renamed admin user (renamed above to “localadmin”) and delete out the temp user.
rm -r /home/temp