Adding a new user with useradd command and the case of /etc/sudoers.d

If you want to create a new user in a terminal client you can easily do so with the useradd command. To use useradd you will need to be a root user (which is a result of typing su root OR  sudo su inside a terminal).

useradd -m -p “” -g users -G “disk,audio,video,floppy,log,network,rfkill,scanner,storage,optical,power,wheel” -s /usr/bin/zsh tester

The above commands will create a user named as tester

Note: you should stay away from the group called adm. Adm is a group, which enables sudo access without a password. The previous might not be desired -if security is a top priority.

When you have created the user, as outlined above, you will next need to set a password for the newly created account:

 passwd tester

After you have written the command above a new user account should exist in your Linux system and the password should be enabled.

 

Additional notes: If you are running Ubuntu/Debian the group wheel is likely replaced with a group sudo. In practice the mean pretty much the same.

Adding stuff to /etc/sudoers.d folder

You can create special permissions for groups and users. One way to do so is to populate sudoers.d folder with appropriate files.

An example:

Sometime ago I had a file named as g_includes in /etc/sudoers.d and it contained:

 

%wheel      ALL=(ALL) ALL  #Gives sudo access for users in the whell group

 

#Commands to execute without password for users in the wheel group. Install pm-utils

%wheel      ALL= NOPASSWD:  /usr/sbin/pm-hibernate #Gives ability to hibernate computer

%wheel      ALL= NOPASSWD:  /usr/sbin/pm-suspend #Gives ability to suspend computer

%wheel      ALL= NOPASSWD:  /usr/sbin/shudown #Reboot and shudown commands

 

For shutdown you can type: shutdown -p

For reboot you can type: shutdown -r

See man shutdown pages for more information. Type: man shutdown when you are in a terminal client. Do note that shutdown commands as listed above will instantly shutdown your computer – so be cautious when using them.