Linux User & Group

Cek User :

    cat /etc/passwd
    atau
    cat /etc/passwd | cut -d: -f1
    root :  x   :  0  :  0  :   root  :  /root  : /usr/bin/zsh
    user : pass : uid : gid : comment : homedir :     shell
    check id user
    id tecmint

Cek Group :

    cat /etc/group
    atau
    cat /etc/group | cut -d: -f1
    kaboxer :  x   : 146 : syahrul,root
    gname   : pass : GID :     users

Add user

    sumber : https://www.tecmint.com/add-users-in-linux/
    mkdir <nama_user>
    useradd <nama_user>
    passwd <nama_user>
  • membuat user untuk directory tertentu
    • useradd -d /home/carloz/coba <nama_user>
  • membuat user dengan user id
    • useradd -u 999 <nama_user>     # default id 500, 501, 502, and so on...
  • membuat user dengan group id
    • useradd -u 1000 -g 500 <nama_user>
  • menambahkan user pada group
    • useradd -G admins,webadmin,developers <nama_user>
  • menambah user tanpa home directory
    • useradd -M <nama_user>
  • menambah user dengan batas akun expiry
    • useradd -e 2014-03-27 <nama_user>
      Next, verify the age of account and password with ‘chage‘ command for user ‘<nama_user>‘ after setting account expiry date.
      chage -l aparna
      Last password change : Mar 28, 2014
      Password expires    : never
      Password inactive   : never
      Account expires     : Mar 27, 2014
      Minimum number of days between password change              : 0
      Maximum number of days between password change              : 99999
      Number of days of warning before password expires       : 7
  • menambah user dengan batas password expiry
    • useradd -e 2014-04-27 -f 45 <nama_user>
  • menambah user dengan shell yang disediakan
    • useradd -s /sbin/nologin <nama_user>
  • menambah user dengan custom command
    • useradd -c "Aku ganteng dan aku bangga" <nama_user>

    contoh hasil

      Add a User with Specific Home Directory, Default Shell and Custom Comment
      This command will create a user ‘ravi‘ with home directory ‘/var/www/tecmint‘, default shell /bin/bash and adds extra information about user. In the above command ‘-m -d‘ option creates a user with specified home directory and the ‘-s‘ option set the user’s default shell i.e. /bin/bash. The ‘-c‘ option adds the extra information about user and ‘-U‘ argument create/adds a group with the same name as the user.
      useradd -m -d /var/www/ravi -s /bin/bash -c "TecMint Owner" -U ravi

      Add a User with Home Directory, No Shell, Custom Comment and User ID
      The following command is very much similar to above two commands, the only difference is here, that we disabling login shell to a user called ‘avishek‘ with custom User ID (i.e. 1019). Here ‘-s‘ option adds the default shell /bin/bash, but in this case we set login to ‘/usr/sbin/nologin‘. That means user ‘avishek‘ will not able to login into the system.
      useradd -m -d /var/www/avishek -s /usr/sbin/nologin -c "TecMint Sr. Technical Writer" -u 1019 avishek

      Add a User without Home Directory, No Shell, No Group and Custom Comment This following command is very different than the other commands explained above. Here we used ‘-M‘ option to create user without user’s home directory and ‘-N‘ argument is used that tells the system to only create username (without group). The ‘-r‘ arguments is for creating a system user.
      useradd -M -N -r -s /bin/false -c "Disabled TecMint Member" clayton