Wednesday, December 30, 2015

useradd usermod groupadd groupmod basics

groupadd groupmod and useradd and usermod
groupmod: change the group name to a GID mapping
groupmod -n  newgroupname oldgroupname ( this command gives a new name to old group)
similiarly -g aoptions help to specify a new GID(it provides anew GID whereas can also replace the old one with the new one

[root@new-host-4 ~]# id ashok
uid=1000(ashok) gid=1000(abc) groups=1000(abc),10(wheel)
[root@new-host-4 ~]# groupmod -n ashok wheel
[root@new-host-4 ~]# id ashok
uid=1000(ashok) gid=1000(abc) groups=1000(abc),10(ashok)
[root@new-host-4 ~]# groupmod -g 1451 abc
[root@new-host-4 ~]# id ashok
uid=1000(ashok) gid=1451(abc) groups=1451(abc),10(ashok)
[root@new-host-4 ~]# groupadd -g 1345 abcd
[root@new-host-4 ~]# groupadd abcd


bash: q: command not found...
[root@new-host-4 ~]# clear
[root@new-host-4 ~]# groupadd -g 3000 shakespeare
[root@new-host-4 ~]# groupadd artists
[root@new-host-4 ~]# tail -5 etc/group
tail: cannot open âetc/groupâ for reading: No such file or directory
[root@new-host-4 ~]# tail -5 /etc/group
abcd:x:5001:ashok
wheel:x:10:ashok,kamal
addd:x:5002:
shakespeare:x:3000:
artists:x:5003:
[root@new-host-4 ~]# usermod -G shakespeare juliet
usermod: user 'juliet' does not exist
[root@new-host-4 ~]# useradd jullet | usermod --G shakespeare jullet
usermod: unrecognized option '--G'
Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -Z, --selinux-user SEUSER     new SELinux user mapping for the user account
 
 the shakespeare group consists of jullet romeo and hamlet and artists group consists of reba dolly and elvis:::
useradd: user 'jullet' already exists
[root@new-host-4 ~]# useradd jullet | usermod -G shakespeare jullet
useradd: user 'jullet' already exists
[root@new-host-4 ~]# id jullet
uid=1005(jullet) gid=1005(jullet) groups=1005(jullet),3000(shakespeare)
[root@new-host-4 ~]# usermod -g shakespeare jullet
[root@new-host-4 ~]# id jullet
uid=1005(jullet) gid=3000(shakespeare) groups=3000(shakespeare)
[root@new-host-4 ~]# usermod -G shakespeare jullet
[root@new-host-4 ~]# id jullet
uid=1005(jullet) gid=3000(shakespeare) groups=3000(shakespeare)
[root@new-host-4 ~]# usermod -G shakespeare romeo | useradd romeo
useradd: user 'romeo' already exists
[root@new-host-4 ~]# id romeo
uid=1006(romeo) gid=1006(romeo) groups=1006(romeo),3000(shakespeare)
[root@new-host-4 ~]# usermod -G shakespeare hamlet | useradd hamlet
useradd: user 'hamlet' already exists
[root@new-host-4 ~]# id hamlet
uid=1007(hamlet) gid=1007(hamlet) groups=1007(hamlet),3000(shakespeare)
[root@new-host-4 ~]# usermod -G artists reba || useradd reba
[root@new-host-4 ~]# id reba
uid=1010(reba) gid=1010(reba) groups=1010(reba),5003(artists)
[root@new-host-4 ~]# usermod -G artists dolly
[root@new-host-4 ~]# id dolly
uid=1008(dolly) gid=1008(dolly) groups=1008(dolly),5003(artists)
[root@new-host-4 ~]# usermod -G artists elvis
[root@new-host-4 ~]# id elvis
uid=1009(elvis) gid=1009(elvis) groups=1009(elvis),5003(artists)
[root@new-host-4 ~]# tail -5 /etc/group
abcd:x:5001:ashok
wheel:x:10:ashok,kamal
addd:x:5002:
shakespeare:x:3000:jullet,romeo,hamlet
artists:x:5003:reba,dolly,elvis
[root@new-host-4 ~]#

[root@new-host-4 ~]# usermod -g abcd ashok
[root@new-host-4 ~]# id ashok
uid=1000(ashok) gid=5001(abcd) groups=5001(abcd),1451(abc),10(ashok)



to remove a group:
groupdel
usermod:: we can change users primary as well as secondary groups using usermod
only root access or sudo command can carry out all these tasks.
usermod -g groupname user changes the current group of user if assigned new group on groupname.
(primary group)
usermod -aG groupname username   does the same a helps to append and prevent the user to be deleted from other supplemental groups (secondary group)

No comments:

Post a Comment