Users
Command | Description |
---|---|
adduser | add a user to the system |
usermod | modify a user account |
userdel | delete a user account and related files |
chage | change user password expiry information |
sudo | run one or more commands as another user |
id | find out user and group names and numeric ID’s (UID or group ID) of the current user or any other user in the server. ID 0 is preserved for the superuser root.user ID’s ranged from 1 to 99 are preserved for system users.user ID’s ranged from 100 to 999 are preserved for special use, but generally they are also used for system users.user ID’s ranged from 1000 and up are preserved for ordinary users like eva, junior etc. |
Add new user
$ sudo adduser eva
$ sudo useradd -c "Description" -m -g group -n adam
$ sudo passwd eva
Switch | Action |
---|---|
-c | Adds comment to the user account |
-m | Creates user home directory in default location, if nonexistent |
-g | Default group to assign the user |
-n | Does not create a private group for the user, usually a group with username |
-M | Does not create a home directory |
-s | Default shell other than /bin/bash |
-u | Specifies UID (otherwise assigned by the system) |
-G | Additional groups to assign the user to |
Disable user
$ sudo passwd -l 'eva'
Delete user
$ sudo userdel -r 'eva'
Lock/unlock student
$ sudo usermod --lock eva
$ sudo usermod --unlock eva
Set the expiration date
$ sudo usermod --expire-date 2020-01-14 eva
Force user to change his password
$ sudo chage --maxdays 60 eva
Groups
Command | Description |
---|---|
groupadd | Adds a new group. |
groupmod | Modifies an existing group’s attributes. |
groupdel | Deletes an existing group. |
The information for groups is stored in /etc/group
$ tail -2 /etc/group
$ grep workers /etc/group
Create new group
$ addgroup workers
Check that a new group was added
$ getent group workers
Change the group name
$ groupmod -n workers new_workers
Change group ID
$ groupmod -g 7000 workers
Remove group
$ delgroup workers
Add existing user to a group
$ usermod -a -G workers eva
Remove user from the group
$ deluser eva workers
Change user primary group
$ usermod -g new_group eva