Change default root/users for security

Hi,
I am new to linux and my profession is not computer sciences, but i am learning.
I do understand a bit about user accounts in Linux: root and users etc.
I would like to change users names for securing login. So how do i do it correctly? Found some information but non is complete. What i would like to do:

  1. delete or rename or disable root
  2. delete or rename dietpi
  3. or create a new user that can act as root

Thanks

You cannot and must not remove the root user as it is essential part of any Linux system. And on DietPi you should not remove the dietpi user, as it is used by some software installs, but we’re going to remove it in a future release. But what you can do is lock those (disable their password so that it isn’t possible to login):

usermod -L root
usermod -L dietpi

But before doing so, create an own user account that you want to use for login, like:

useradd -mk /etc/skel -s /bin/bash eglider86
passwd eglider86

This creates a user named “eglider86” with its home directory /home/eglider86, including the default files added from /etc/skel and bash as login shell. The second command is to assign a password. Without a root user account, you may also allow this new user to run commands with root privileges via sudo:

usermod -aG sudo eglider86
1 Like

Thank you so much. Real education here!
Yes i have realized the dietpi account is needed, since after deleting it i was not able to add softwares…
Ok. I follow your points.
Thanks again

if you like to keep local access as root user (backup/fall back/emergency access), you could simply disable SSH login for user root.

i have added new user to sudo, but the system keeps asking for user password that did not happen with dietpi user

The first time you use sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.

Thank you!

You can disable the password prompt as well:

echo 'eglider86 ALL=(ALL:ALL) NOPASSWD: ALL' > /etc/sudoers.d/eglider86

aha! none of the googling i did while trying to setup a new user included this part about making /etc/skel. had i not found this post i would still be banging my head on this topic.

Update…

The usermod command did not add the user to the sudo group for me. This worked. Hopefully this will help someone else who ran into the same thing as me:

sudo visudo -f /etc/sudoers.d/username

then enter the following in the file and save:

username ALL=(ALL:ALL) ALL

Hmm usermod -aG sudo username definitely adds it to the group, as long as no error message is returned. For it to have the intended result, there is a line in /etc/sudoers required (and should be present by default):

%sudo   ALL=(ALL:ALL) ALL

This is basically the same syntax you use to grant an individual user sudo permissions, but with the % is applies to the respective group.

However, creating an own config file is probably the cleanest and definitely the most compatible solution anyway, as not all distros come with the sudo group or the above entry in the default config file.