Linux User Account & Groups Settings Use in Terminal

kybagul
  5 years ago
  -1

1. Add New User

For this tutorial we are using adduser command for examples. Following command will create new user named ‘paul’ on your system

$ sudo adduser paul
Adding user 'paul' ...
Adding new group 'paul' (1001) ...
Adding new user 'paul' (1001) with group 'paul' ...
Creating home directory '/home/paul' ...
Copying files from '/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for paul
Enter the new value, or press ENTER for the default
    Full Name []: Paul Baker
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n] Y

By default above command will create users home directory as /home/
$ sudo adduser paul --home=/var/home/paul

You can also specify any other shell for user in place of default, use –shell switch followed by shell name as below.
$ sudo adduser paul --shell=/bin/bash

If you don’t want to create users home directory. You can use –no-create-home switch with adduser command as below.
$ sudo adduser paul –no-create-home

2. View all Users

Enter below command and find 1000:1000 this is first user is 1001 and 1002, 1003 ….. sequence more users.
$ cat /etc/passwd

kamlesh:x:1000:1000:Kamlesh Bagul:/home/kamlesh:/bin/bash
paul:x:1001:1001:,,,:/home/paul:/bin/bash
rahul:x:1002:1002::/home/rahul:

3. View User Groups

View current user group
$ groups

adm cdrom sudo dip plugdev lpadmin sambashare
Above groups are default for Administration

Show paul groups
$ groups paul

paul : paul

4. Add Groups for User

You can set groups for users.
$ sudo adduser paul adm
$ sudo adduser paul cdrom

Now add adm & cdrom group for paul user.

Add multiple Group at one time
$ sudo usermod -aG dialout,cdrom,paul paul

Make Administration Account, use sudo group for adminstration.
$ sudo adduser paul sudo

View paul Groups
$ groups paul
paul : paul dialout cdrom sudo

5. Delete User from System

Now its good to lock or delete any user from system which is no longer required. Use the following command to delete any user from system.
$ sudo deluser paul

The above command will not delete users home directory. If you also want to delete users home directory add –remove-home parameter with command, For example below command will delete user paul and their home directory permanently.
$ sudo deluser paul --remove-home

You may also take backup of users home directory before deleting it using following command.
$ sudo deluser paul --remove-home --backup  --backup-to /var/archives/

6. Remove Groups for User

$ sudo deluser paul sudo
Removing user 'paul' from group 'sudo' ...
Done.

View paul Groups
$ groups paul
paul : paul dialout cdrom