Or, the quick bookmark for configuring local users
March 5, 2018This is the first in a series of posts that is meant to dump some personal notes that I've kept for quite some time. Most of the information found below can be gathered by simply typing in the command listed followed by a --help or preceded with the man or info command. The real challenge, most of the time, is in remembering the command or file name and location. Both of those things as well as explanations and examples are listed below.
/etc/passwd fileThis file contains all user accounts on the system. Below is an example of an entry in /etc/passwd.
1 2 3 4 5 6 7
leo:x:1005:1005:Leo Chavez,,,:/home/leo:/bin/bash
leo is the username.x is the password placeholder. If no password is set, a ! will appear instead.1005 is the UID (user ID).1005 is the GID (group ID).Leo Chavez is the full name of the user./home/leo is the location of the home directory./bin/bash is the location of the user's default terminal./etc/shadow fileThis file contains all users and hashed passwords, but cannot be read by normal users. By default, root will have read/write access and the shadow group will have read access. Therefore, to see this file, you'll have to elevate your privileges with sudo or su to root.
1 2 3 4 5 6 7 8 9
leo:$6$7iU2.3kT$c/brL1Ydgicae.LkNKYsoAMq1.2J71:17594:0:99999:7::17897:
leo is the username$6$ represents the hashing algorithm SHA512. $5$ (SHA256) is also common.17594 represents the number of days after Jan 1, 1970 that the password was changed.0 is how many days a user must wait before changing their password again.99999 is how many days a user can keep their password before being forced to change it.7 is the amount of days prior to the forced password change a user is warned.17897 is the number of days from Jan 1, 1970 until account expiry/etc/group fileThis file contains a list of all groups on the system.
1 2 3 4
sambashare:x:127:leo
sambashare is the group name.127 is the group ID./etc/gshadow would be the group version of /etc/shadow.
useradd commandThe useradd command will create users as well as define their home folder location, set an account expiration date and define the default shell.
useradd leo -museradd leo -f 7useradd leo -e 2018-12-31useradd leo -m -e 2019-01-01passwd commandThe passwd command will set the password for yourself when used alone passwd or of another use when the user is defined passwd leo. This is typically done as root or with sudo. This must be done before the new user can log in.
userdel commandThe userdel leo command will remove a user from the system, but leave the files behind. To remove the files as well, use userdel -r leo
groupadd commandThe groupadd command will add new groups to the system. Adding the group Sales can be done with groupadd Sales.
usermod commandThe usermod command will make modifications to users like group associations and home directory changes.
usermod -g marketing leousermod -G sales leousermod -a -G warehouse leousermod -l nate -m -d /home/nate leogroups and id commandsThe groups command will show which groups the current user is assigned to. To find out this info about another user, add the username groups nate. The id command will show similar information as well as User ID and any Group ID associated with the users or groups. id nate will show ID information about Nate.