# Linux Basics/User management
## User management functions

* Functions: adding, deleting user, setting password, modifying
* Adding user: adduser(under Ubuntu), useradd

### Adding user

Syntax:
Options:
* -u number: setting the user id (UID)
* -c: note
* -g group: setting group membership
* -d /home/user: setting HOME folder to /home/user.
* -s /bin/bash: default shell (here the user gets bash as default
* -G group1, group2: separating them with commas, if the user is member of other groups
* -m -k /home/existing <username>: it creates the home folder based on an existing user's home folder.
** -m switch refers to create home directory, -k indicates where we want to copy the default files from (e.g. /etc/skel -> the skeleton folder of the home folder)
so the command looks like this:

### getent

User information: getent
If we want to get information about infotech group:

### /etc/passwd file

Location of user data: /etc/passwd
Content of /etc/passwd is like:
Passwd file's entries are separated with comma, and the explanation of the fields are the following:
* Username.
* Encrypted password.
* User ID(uid).
* Group ID (gid).
* Full name and other information
* Home folder
* Selected shell

### /etc/shadow file

Content of /etc/shadow file is like:
As with the passwd file, each field in the shadow file is also separated with ":" colon characters, and are as follows
* Username, up to 8 characters. Case-sensitive, usually all lowercase. A direct match to the username in the /etc/passwd file.
* Password, 13 character encrypted. A blank entry (eg. ::) indicates a password is not required to log in (usually a bad idea), and a ``*'' entry (eg. :*:) indicates the account has been disabled.
* The number of days (since January 1, 1970) since the password was last changed.
* The number of days before password may be changed (0 indicates it may be changed at any time)
* The number of days after which password must be changed (99999 indicates user can keep his or her password unchanged for many, many years)
* The number of days to warn user of an expiring password (7 for a full week)
* The number of days after password expires that account is disabled
* The number of days since January 1, 1970 that an account has been disabled
* A reserved field for possible future use

### chage

Changing user rules: chage
We can regulate with changing it when will the password of a user expires.
For example, output of chage -l joska will display the data for it:
We want joska user's password to expire in 10 days:
When will we want joska's password to expire?
Lockdown after inactive days
We lock joska's password after 10 inactive days.

### User password

User password: passwd
Changing own password:
With superuser privilege we can change anybody's password:
Storing password encrypted: /etc/shadow
Generating password:

### chfn

Modifying user data: chfn
We need finger package for it.
e.g.:
Kapcsolók:
* -f, --full-name
* -o, --office -- office room number
* -p, --office-phone - office phone number
* -h, --home-phone - home phone number

### Deleting user

Deleting user: deluser, userdel
It's recommended to regulate it with help of /etc/deluser.conf, We should look up deluser.conf(5) manual.
e.g.:

### Handling user groups

Creating group: addgroup, groupadd
Location of group data: /etc/group
/etc/group file can be edited manually (text editor, mcedit, nano etc) by root.
A group is created with every user's name (like in case of kathy user a kathy group is created).
Adding to group:
* We add kathy to infotech group
Csoportból kivétel:
* We delete kathy from infotech group

### Handling user groups (and user data)

„usermod” command:
* Changing user accounts.
Adding user mary to infotech group:
(For -a the group name is appended, so the other group remains for that user. If we omit -a, then all the existing groups the user is assigned in gets deleted for that user.
Usermod command's other switches:
* -u value user: it changes user ID (UID)
* -g group user: it changes user group (e.g. usermod -g infotech mari)
* -G group1,group2: it adds the user to the given groups (but without appending)
* -L user: it locks the access of the user / bans the user (so you can't log in)
* -e value: expire date (--expiredate)
* -U user: unlocks the ban from the user
* -d user: setting new home folder (--home)
* -s user: setting shell (--shell)
id command:
Requesting information about the user.
group member:

## User accounts and handling "default"
### User account settings

In /etc/login.defs directory/file there can be set some properties for users. For example, where should the user emails be stored.
Logging failed logins into /var/log/faillog file:
Logging unknown usernames in case of failed logins:
Logging successful logins:
Controlling passwords. By default, when it's gonna expire, when the user can change it, what's the minimum length of the password, and when the warning should be:
User ID minimum and maximum ID's in case of useradd:
Minimum and maximum number group IDs:
Denying login after this number of fails:
The length of lockdown after exceeding the number of unsuccessful logins:

### User defaults

/etc/default folder contains it.
E.g. /etc/default/useradd
* /etc/skel folder contains the base home directory's content.