Change default root/users for security Topic is solved

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
eglider86
Posts: 54
Joined: Sat Mar 20, 2021 10:12 am

Change default root/users for security

Post by eglider86 »

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
User avatar
MichaIng
Site Admin
Posts: 3349
Joined: Sat Nov 18, 2017 6:21 pm

Re: Change default root/users for security

Post by MichaIng »

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):

Code: Select all

usermod -L root
usermod -L dietpi
But before doing so, create an own user account that you want to use for login, like:

Code: Select all

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:

Code: Select all

usermod -aG sudo eglider86
eglider86
Posts: 54
Joined: Sat Mar 20, 2021 10:12 am

Re: Change default root/users for security

Post by eglider86 »

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
User avatar
Joulinar
Posts: 5927
Joined: Sat Nov 16, 2019 12:49 am

Re: Change default root/users for security

Post by Joulinar »

if you like to keep local access as root user (backup/fall back/emergency access), you could simply disable SSH login for user root.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
eglider86
Posts: 54
Joined: Sat Mar 20, 2021 10:12 am

Re: Change default root/users for security

Post by eglider86 »

i have added new user to sudo, but the system keeps asking for user password that did not happen with dietpi user
User avatar
Joulinar
Posts: 5927
Joined: Sat Nov 16, 2019 12:49 am

Re: Change default root/users for security

Post by Joulinar »

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.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
eglider86
Posts: 54
Joined: Sat Mar 20, 2021 10:12 am

Re: Change default root/users for security

Post by eglider86 »

Thank you!
User avatar
MichaIng
Site Admin
Posts: 3349
Joined: Sat Nov 18, 2017 6:21 pm

Re: Change default root/users for security

Post by MichaIng »

You can disable the password prompt as well:

Code: Select all

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