Each user is associated with a unique numerical identification number called a user ID (UID). Likewise, each group is associated with a group ID (GID). A user who creates a file is also the owner and group owner of that file. The file is assigned separate read, write, and execute permissions for the owner, the group, and everyone else. The file owner can be changed only byroot, and access permissions can be changed by both the root user and file owner.
Now we can create a user named AP2V and can see what all steps and files getting involved forcreating a new user in linux.
# root@ap2v:~# useradd newuser
# root@ap2v:~# passwd newuser
New password:
Repeat password:
The username is the only information required to add a new user; however, for exam prospective you should know some additional command-line arguments for useradd. The useradd command creates the account, but the account is locked.To unlock the account and create a password for the user, use the command passwd [username].
By default, the user’s home directory is created and the files from /etc/skel/ are copied into it.
User Administration Commands:
- useradd – To create a User
- usermod – To Modify user
- userdel – To delete a user
While using above commands of creating a user it reflects to three files
- /etc/passwd
- /etc/group
- /etc/shadow
# vi /etc/passwd
AP2V:x:500:500:linux:/home/AP2V:/bin/bash
| | | | | | |
1 2 3 4 5 6 7
1. Username: It is used when user logs in. It should be between 1 and 32 characters in length.
2. Password: An x character indicates that encrypted password is stored in /etc/shadow file.
3. User ID: Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UID’s 1-99 reserved for other predefined accounts. Further UID 100-999 are reserved for administrative and system accounts/groups.
4. Group ID (GID): The primary group ID (stored in /etc/group file) User ID info: The comment field. It allow you to add extra information about the users such a user’s full name, phone number etc.
5. User ID Info: The comment field. it allow you to add extra information about the users such as user’s full name, Phone number etc.
6. Home directory: The absolute path to directory the user will be in when they log in. If this directory does not exists then users directory becomes / .
7. Command / Shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell.
Please note that it does not have to be a shell
# vi /etc/shadow
AP2V:$!$nfsoadfnssdfasdfv*^$bosfs:14880:0:9999:7
| | | | | |
1 2 3 4 5 6
1. User name: It is your login name.
2. Password: It your encrypted password. The password should be minimum 6-8 characters long including special characters/digits.
3. Last password change (lastchanged): Days since that password was last changed.
4. Minimum: The minimum number of days required between password change. The number of days left before the user is allowed to change password.
5. Maximum: The maximum number of days the password is valid (after that user is forced to change password)
6. Warn: The number of days before password is expire that user is warned that his/her password must be changed.
# vi /etc/group
AP2V:x:503:AP2V,linuxusers
| | | |
1 2 3 4
1. Group Name:
- It is the name of the group. If you run ls –la command. You will see this name printed in the group field.
2. Password: Generally password is not used, hence it is empty. It can store encrypt password. This is useful to implement privileged groups.
3. Group ID (GID): Each user must be assigned a group id. You can see this number in your /etc/passwd file.
4. Group list: It is a list user names of users who are members of the group. The user names must be separated by commas.