We will discuss how to create new user, modify existing user details and password.
Types of users UID
root 0
system 1-999
normal 1000-6000
System user is again divided into two types- Kernel and Application users
Kernel :Like ping, shutdown have UID between 1-200
Application: Like Mysql have UID between 201-999
Adding user:
Command:
useradd <user>
Eg:
useradd star1
Note that a line will be added at the bottom of /etc/passwd file as below
star1:x:1076:1078::/home/star1:/bin/bash
If password not set for user then the user will be locked.
Setting a password for the created user:
command:
passwd <user>
Eg:
#passwd star1
Changing password for user star1.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
You can switch user from one user to another using "su -" command
Eg:
su - star1
Each row in /etc/passwd has some meaning
Eg:
star1:x:1076:1078::/home/star1:/bin/bash
Each is separated by :
1. Username
2. password pointer
3. User ID
4. Group ID
5. Comment (In above example it is blank)
6. User home directory path
7. Shell assigned to the user
All the above information are taken from /etc/login.defs
The user password is stored in /etc/shadow file in SHA5 encrypted format.
Eg:
star1:$6$EalMg2fD$BPhfTEC8yo0xEvrmFEYBVZ/ZUW/j7dmdRA4392GqFy7n5GENMqRg4bbBr1yMBdKTX1cf3.z2mjH1GGVXKeuH6.:16683:0:99999:7:::
Highlighted above is the password of the user star1 in encrypted format.
Line has 9 fields.
1. User
2. Encrypted Password
3. The date of the last password change since Jan 1, 1970.
4. The number of days the user will have to wait to change password again
5. The number of days after which the user will have to change password
6. The number of days before a password is going to expire
7. Password inactivity period
8. The date of expiration of the account since Jan 1, 1970.
9. This field is reserved for future use.
By default adding user using useradd will create UID, home directory automatically.
If we need to give our own UID, home directory then below command helps.
Ex:
useradd -u 5555 -s /bin/csh -c "star2xxx@gmail.com" -d /home/myhome star2
-c COMMENT
-d home directory of the new account
-e expiration date of the new account
-f password inactivity period of the new account
-g GID
-G list of supplementary groups of the new account
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-p, --password PASSWORD encrypted password of the new account
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
To delete user:
userdel <user>
Eg:
userdel star1
Above command will not delete the home directory of the user star1
To remove entire home directory along with the user use -r in userdel command
eg:
userdel -r star2
Types of users UID
root 0
system 1-999
normal 1000-6000
System user is again divided into two types- Kernel and Application users
Kernel :Like ping, shutdown have UID between 1-200
Application: Like Mysql have UID between 201-999
Adding user:
Command:
useradd <user>
Eg:
useradd star1
Note that a line will be added at the bottom of /etc/passwd file as below
star1:x:1076:1078::/home/star1:/bin/bash
If password not set for user then the user will be locked.
Setting a password for the created user:
command:
passwd <user>
Eg:
#passwd star1
Changing password for user star1.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
You can switch user from one user to another using "su -" command
Eg:
su - star1
Each row in /etc/passwd has some meaning
Eg:
star1:x:1076:1078::/home/star1:/bin/bash
Each is separated by :
1. Username
2. password pointer
3. User ID
4. Group ID
5. Comment (In above example it is blank)
6. User home directory path
7. Shell assigned to the user
All the above information are taken from /etc/login.defs
The user password is stored in /etc/shadow file in SHA5 encrypted format.
Eg:
star1:$6$EalMg2fD$BPhfTEC8yo0xEvrmFEYBVZ/ZUW/j7dmdRA4392GqFy7n5GENMqRg4bbBr1yMBdKTX1cf3.z2mjH1GGVXKeuH6.:16683:0:99999:7:::
Highlighted above is the password of the user star1 in encrypted format.
Line has 9 fields.
1. User
2. Encrypted Password
3. The date of the last password change since Jan 1, 1970.
4. The number of days the user will have to wait to change password again
5. The number of days after which the user will have to change password
6. The number of days before a password is going to expire
7. Password inactivity period
8. The date of expiration of the account since Jan 1, 1970.
9. This field is reserved for future use.
By default adding user using useradd will create UID, home directory automatically.
If we need to give our own UID, home directory then below command helps.
Ex:
useradd -u 5555 -s /bin/csh -c "star2xxx@gmail.com" -d /home/myhome star2
-c COMMENT
-d home directory of the new account
-e expiration date of the new account
-f password inactivity period of the new account
-g GID
-G list of supplementary groups of the new account
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-p, --password PASSWORD encrypted password of the new account
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
To delete user:
userdel <user>
Eg:
userdel star1
Above command will not delete the home directory of the user star1
To remove entire home directory along with the user use -r in userdel command
eg:
userdel -r star2
Comments
Post a Comment