A brief description on user creation and management
There are many types of users on a Linux system. Regular, system, and the all powerful super user. However, this guide is about making regular users. And giving them permissions to do things.
In order to create and mange users you'll need to use sudo
or be root
To create a user named bob:
It is best practice to utilize adduser, this will create the user, their group, and their home directory. The useradd on Debian based systems is a low level tool designed for making system level users. Redhat based distros do not have this and will obfuscate the difference, and make regular users by default. TLDR; adduser not useradd.
The user is not alive but they don't have password! Therefore, won't be able to login.
To give the user a password:
passwd
is the actual command not a misspelling of "password" do not try to correct this. There are many "typos" that are built-in linux commands,
Once the user is created and a password is set you'll be able to login as bob
User bob has logged in but doesn't show up in the sudoers file let's troubleshoot:
Since we are utilizing a Redhat Distribution we need to add bob to the wheel
group.
If you are unsure what distribution type you're on you can run cat /etc/os-release
the ID Like section will tell you the closest relative to the actual distribution.
While the actual distro is belows Amazon Linux 2 we see the ID_LIKE
is "centos rhel fedora"
centos is an open source copy of Red Hat. rhel is an abbreviation for Red Hat Enterpise Linux. And Fedora is the development OS from which Red Hat inherits its updates and changes.
An example of Debian based distributions would be Ubuntu, PopOs, Raspbian.
Usermod is a command that allows you to change the attributes of a user, generally this utilized to change either the primary group or add groups to the user to allow them certain permissions. The most popular is adding people to the pre-verified sudo group.
The syntax for usermod is like any other built-in command: command [options] (arguments)
in the case of usermod
the order of arguments is groups desired to be added followed by the user.
Now that we know our distribution, sudo group, and user to be changed we can give bob the permissions he needs.
We've given bob a lot of power, the same as us. If bob were to run sudo -i
or sudo su -
and actually become root he could do whatever he likes. Even more concerning is that bob has quit and now his user on the system needs to be removed. Leaving a user like bob who can utilize sudo is a threat to our security posture.
To clean up bob's home directory, mail directory, groups, and permissions:
Please note that not all options mean the same thing in all commands this is even more true for non-bulit-in commands. Always refer to the man pages before utilizing any options. And check the official documentation for any command line tools you've installed.