Change Default Admin Username

Mr_Bob

Verified User
Joined
Sep 25, 2021
Messages
10
Hi all - first post!

I'm taking my first crack at managing my own VPS, and so far things are going well. Fixed a few quirks already so I'm feeling more confident :).

Anyway, to the question. I chose to have a personal license so I'm limited to only one Directadmin account (fine for my purposes). Of course, the Directadmin installer creates a default "admin" username. If possible, I'd really like to change this username as I unfortunately don't have the ability to create another admin user and delete the default admin user, which would be easier, per my license.

I did find a script in /usr/local/directadmin/ titled change_username.sh - and looking at the contents this seems to be exactly what I want to use. I'd just navigate to the directory and run

bash change_username.sh admin mynewname

My question though is that I'm sure this will work for any normal user situation, but can I do this to an admin user without causing problems? Apologies for the amateur hour question; I just don't know enough about Directadmin to know whether or not all dependencies will be changed that need to be for an admin level user.
 
Hello,

This worked in my testing, especially well after this:
https://www.directadmin.com/features.php?id=2984
change_username.sh: CRON: also swap paths

Now, afterwards,

1) Resuspend any suspended domains
2) Check for any custom docroots using the old '/home/admin' path, update, and rebuild_confs
3) Check the backup cron path (eg '/home/admin/admin_backups') in /usr/local/directadmin/data/admin/backup.conf (setting may look like this: local_path=/home/admin/admin_backups)

Keep in mind the many plugins and scripts may specify the /home/admin path instead of ~ or $HOME, so you may see buggy behavior with some scripts/plugins, etc., just by changing the admin username, and consequently, and admin $PATH.

Let us know if you have any problems!
 
Excellent - thank you! This seems to have worked. I'll repot back in the future if there's anything amiss, but I imagine that will primarily just be an exercise in editing paths.
 
Apologies - I'd normally add in an edit but it doesn't look my account can edit yet.

Went in and did checks, and it appears Directadmin's script does a pretty good job replacing the old "admin" name, including in places @scriptkitty referenced. I'm impressed! Confirmed at least the old /home/admin/ path is gone from everywhere (expect logs) via grep and manually checked the referenced files and directories.

That said, it looks like the majority of programs controlled via Custombuild (ie PHP, Apache, etc) get along just fine with the admin name change. However, any database programs (and programs that use databases in the background like Roundcube) need to be rebuilt. In some cases (like PHPMyAdmin) you'll just get errors like "admin @ localhost denied" because the conf is looking for the admin user. Some programs just won't run. I guess probably the easiest thing to do is rebuild all your packages, but it does look as if it only really impacts database dependent programs.

Hope that helps anyone in the future making a change! It might be a good addition in the future that the change_username.sh also checks for admin user connections to these programs and either rebuilds as part of the execution or displays a message to the user like "Primary administrator user changed! Please rebuild the following packages in CustomBuild:"
 
In some cases (like PHPMyAdmin) you'll just get errors like "admin @ localhost denied" because the conf is looking for the admin user. Some programs just won't run. I guess probably the easiest thing to do is rebuild all your packages, but it does look as if it only really impacts database dependent programs.

Regarding the issue mentioned, I don't think the `admin @ localhost` was created by default. I also think the admin username from DA does not relate to the username for the database program. The database program by default is using da_admin. So, I'm confused why did the database program / phpmyadmin looking for the username admin@localhost that was not created by DA itself.


Some programs just won't run.

It is better to specify what the other programs that don't run after you changed the username


Might be best to change the admin username after you have just set up a new directadmin server. This is what I do when setting up new server with DA.
 
Last edited:
Back
Top