Tuesday, March 22, 2016

Users and groups on the Linux

Hi all, today I want to take some timeout from Openstack and explain a little bit about managing linux groups and users.

Agenda:
    - Group management (groupaadd, groupdel)
    - User management (useradd, userdel, usermod)
    - How to assign password to user (passwd)
    - How to force user to change password on next login



Group management:
   
          1. create new group:   # groupadd new-1
          2. check created group under /etc/group
              output is:
                                         new-1:x:1001:
                                              |            |
                                          name       id

           3. delete group: # groupdel new-1


User managment:
            
           1. Add new user: # useradd -u 2000 -g 1001 user1   -d /home/user1  -s /bin/bash
                                                              |              |            |                    |                   |               
                                                            uid       primary    new             home            shell 
                                                                       group id    name         directory


           2. For checking new user see  /etc/passwd
               output is:
                                          user:x:2000:1001::/home/user:/bin/bash
                                             |           |       |               |                |
                                         name    user group      home        shell 
                                                        id      id        directory


             Exist few types of groups:
                       1. Primary - default user group where user will create files etc.
                       2. Secondary - you can add any group, so user will have any access from                                                      these groups              

            3. For modification user use: # usermod -u 2001 user1 etc...
                or for adding additional (secondary groups use) # usermod -G www,ftp user1

            4. For removing user use # userdel -r user1 (-r remove home directory)

            5. Exist option lock/unlock user, locked user cant login:
                                      # usermod -L user1 - locked
                                      # usermod -U user1 - unlocked 


 
How to assign password to user (passwd):

            There are 2 ways:

            1. # passwd user

            2. If you want see pass you typed, use: # echo 'password' | passwd --stdin user 


How to force user to change password on next login
             1. #chage -d 0 user  - changing password in the next login

             2. # chage -M 10 user - changing password each 10 days
             3. # chage -l user - all information about user password
                                          or
                 /etc/shadow 



No comments:

Post a Comment