Where Online Learning is simpler!



In the examples below, you will see several usage of the commands for useradd, userdel, usermod, groupadd, groupdel, and groupmod. Since the examples are self-explanatory, I suggest you should see the manual pages at bottom of this page for any of the commands you have question.

$ whatis useradd

useradd - administer a new user login on the system

$ whatis userdel

userdel - delete a user's login from the system

$ whatis usermod

usermod - modify a user's login information on the system

$ whatis groupadd

groupadd - add (create) a new group definition on the system

$ whatis groupdel

groupdel - delete a group definition from the system

$ whatis groupmod

groupmod - modify a group definition on the system


Examples:

# hostname

MySolaris

# id

uid=0(root) gid=0(root) groups=0(root),1(other),2(bin),3(sys),4(adm),5(uucp),6(mail),7(tty),8(lp),9(nuucp),12(daemon)

# which useradd

/usr/sbin/useradd

# useradd

UX: useradd: ERROR: invalid syntax.

usage: useradd [-u uid [-o] | -g group | -G group[[,group]...] |-d dir | -b base_dir |

-s shell | -c comment | -m [-k skel_dir] | -f inactive |

-e expire | -A authorization [, authorization ...] |

-P profile [, profile ...] | -R role [, role ...] |

-K key=value | -p project [, project ...]] login

useradd -D [-g group | -b base_dir | -f inactive | -e expire

-A authorization [, authorization ...] |

-P profile [, profile ...] | -R role [, role ...] |

-K key=value ... -p project] | [-s shell] | [-k skel_dir]

# useradd -d /export/home/newuser -m -s /bin/ksh -c "newuser" newuser

80 blocks

# grep -i newuser /etc/passwd

newuser:x:102:1:newuser:/export/home/newuser:/bin/ksh

# grep -i newuser /etc/shadow

newuser:*LK*:::::::

# passwd -r files newuser

New Password:

Re-enter new Password:

passwd: password successfully changed for newuser

# grep -i newuser /etc/shadow

newuser:$5$w6al9BVN$OqE5zQFhqRDuKu0aF8FXb6QBPUm6GpNEcUK8rsxGS62:15144::::::

# groupadd newgroup

# grep newgroup /etc/group

newgroup::100:

# groupadd

UX: groupadd: ERROR: invalid syntax.

usage: groupadd [-g gid [-o]] group

# usermod

UX: usermod: ERROR: Invalid syntax.

usage: usermod -u uid [-o] | -g group | -G group[[,group]...] |

-d dir [-m] | -s shell | -c comment |

-l new_logname | -f inactive | -e expire |

-A authorization [, authorization ...] | -K key=value ... |

-P profile [, profile ...] | -R role [, role ...] login

# usermod -g newgroup newuser

# grep -i newuser /etc/passwd /etc/group /etc/shadow

/etc/passwd:newuser:x:102:100:newuser:/export/home/newuser:/bin/ksh

/etc/shadow:newuser:$5$w6al9BVN$OqE5zQFhqRDuKu0aF8FXb6QBPUm6GpNEcUK8rsxGS62:15144::::::

# grep -i newuser /etc/passwd

newuser:x:102:100:newuser:/export/home/newuser:/bin/ksh

# grep -i newgroup /etc/group

newgroup::100:

# grep -i 102 /etc/passwd

newuser:x:102:100:newuser:/export/home/newuser:/bin/ksh

# su - newuser

Oracle Corporation SunOS 5.11 snv_151a November 2010

$ id

uid=102(newuser) gid=100(newgroup) groups=100(newgroup)

$ groups

newgroup

$ id

uid=102(newuser) gid=100(newgroup) groups=100(newgroup)

$ exit

# ssh -l newuser 192.168.1.5

The authenticity of host '192.168.1.5 (192.168.1.5)' can't be established.

RSA key fingerprint is 16:c0:ec:37:f8:e3:0e:c4:03:ea:ff:a0:14:38:94:2d.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.1.5' (RSA) to the list of known hosts.

Password:

Last login: Sat Jun 18 22:58:19 2011 from mysolaris

Oracle Corporation SunOS 5.11 snv_151a November 2010

$ id

uid=102(newuser) gid=100(newgroup) groups=100(newgroup)

$ who am i

newuser pts/3 2011-06-18 22:58 (mysolaris)

$ whoami

newuser

$ groups

newgroup

$ id

uid=102(newuser) gid=100(newgroup) groups=100(newgroup)

$ id -g

100

$ id -u

102

$ exit

Connection to 192.168.1.5 closed.

# exit

# id

uid=0(root) gid=0(root) groups=0(root),1(other),2(bin),3(sys),4(adm),5(uucp),6(mail),7(tty),8(lp),9(nuucp),12(daemon)

# grep -i newuser /etc/passwd

newuser:x:102:100:newuser:/export/home/newuser:/bin/ksh

# usermod

UX: usermod: ERROR: Invalid syntax.

usage: usermod -u uid [-o] | -g group | -G group[[,group]...] |

-d dir [-m] | -s shell | -c comment |

-l new_logname | -f inactive | -e expire |

-A authorization [, authorization ...] | -K key=value ... |

-P profile [, profile ...] | -R role [, role ...] login

# usermod -s /bin/bash newuser

# grep -i newuser /etc/passwd

newuser:x:102:100:newuser:/export/home/newuser:/bin/bash

# groupadd developers

UX: groupadd: developers name too long.

# groupadd dev

# grep -i dev /etc/group

developers::101:

dev::102:

# groupdel developers

# grep -i dev /etc/group

dev::102:

# usermod -g dev newuser

# grep -i newuser passwd

newuser:x:102:102:newuser:/export/home/newuser:/bin/bash

# su - newuser

Oracle Corporation SunOS 5.11 snv_151a November 2010

newuser@MySolaris:~$ id

uid=102(newuser) gid=102(dev) groups=102(dev)

$ id -g

102

$ groups

dev

$ exit

logout

#

# id

uid=0(root) gid=0(root) groups=0(root),1(other),2(bin),3(sys),4(adm),5(uucp),6(mail),7(tty),8(lp),9(nuucp),12(daemon)

# su - newuser

Oracle Corporation SunOS 5.11 snv_151a November 2010

$ id

uid=102(newuser) gid=102(dev) groups=102(dev)

$ who am i

$ whoami

newuser

$ groups

dev

$ pwd

/export/home/newuser

$ grep -i admin /etc/group

sysadmin::14:

$ id

uid=102(newuser) gid=102(dev) groups=102(dev)

$ exit

logout

# id

uid=0(root) gid=0(root) groups=0(root),1(other),2(bin),3(sys),4(adm),5(uucp),6(mail),7(tty),8(lp),9(nuucp),12(daemon)

# groupadd admin

# grep -i admin /etc/group

sysadmin::14:

admin::103:

$ exit

logout

# usermod

UX: usermod: ERROR: Invalid syntax.

usage: usermod -u uid [-o] | -g group | -G group[[,group]...] |

-d dir [-m] | -s shell | -c comment |

-l new_logname | -f inactive | -e expire |

-A authorization [, authorization ...] | -K key=value ... |

-P profile [, profile ...] | -R role [, role ...] login

# usermod -G dev,admin newuser

# grep -i newuser /etc/passwd

newuser:x:102:102:newuser:/export/home/newuser:/bin/bash

# su - newuser

Oracle Corporation SunOS 5.11 snv_151a November 2010

$ id

uid=102(newuser) gid=102(dev) groups=102(dev),103(admin)

$ groups

dev admin

$ id -g

102

$ id -G

102 103

$ id -u

102

$ id

uid=102(newuser) gid=102(dev) groups=102(dev),103(admin)

$ exit

logout

# groupdel admin

# groupdel dev

# grep -i dev /etc/group

# grep -w admin /etc/group

# grep -i newuser /etc/passwd

newuser:x:102:102:newuser:/export/home/newuser:/bin/bash

# id

uid=0(root) gid=0(root) groups=0(root),1(other),2(bin),3(sys),4(adm),5(uucp),6(mail),7(tty),8(lp),9(nuucp),12(daemon)

# cd /export/home

# ls -l

total 3

drwxr-xr-x 2 newuser other 9 2011-06-18 23:06 newuser

# pwd

/export/home

# useradd dev

# userdel dev

# groupadd dev

# usermod -g dev newuser

# ls -ld newuser

drwxr-xr-x 2 newuser dev 9 2011-06-18 23:06 newuser

#groupdel dev

# ls -ld newuser

drwxr-xr-x 2 newuser 101 9 2011-06-18 23:06 newuser

# groupadd admin

root@MySolaris:/export/home# grep -w admin /etc/group

admin::101:

# chown newuser:admin newuser

drwxr-xr-x 2 newuser admin 9 2011-06-18 23:06 newuser

# groupdel admin

# ls -ld newuser

drwxr-xr-x 2 newuser 101 9 2011-06-18 23:06 newuser

# userdel

usage: userdel [-r] login

# pwd

/export/home

# ls -l

total 3

drwxr-xr-x 2 newuser 101 9 2011-06-18 23:06 newuser

# userdel -r newuser

# pwd

/export/home

# grep -i newuser /etc/passwd /etc/shadow /etc/group

# groupmod

UX: groupmod: ERROR: invalid syntax.

usage: groupmod -g gid [-o] | -n name group

# groupmod

UX: groupmod: ERROR: invalid syntax.

usage: groupmod -g gid [-o] | -n name group

# groupadd dev

# grep -i dev /etc/group

dev::101:

# groupmod

UX: groupmod: ERROR: invalid syntax.

usage: groupmod -g gid [-o] | -n name group

# groupmod -n newdev dev

# grep -i dev /etc/group

newdev::101:

# groupmod -g 104 newdev

# grep -i 104 /etc/group

newdev::104:

# groupmod -g 101 newdev

newdev::101:

# groupdel newdev

# groupdel newgroup

Please click on "

man useradd " to see the Manual Page for this command.

Please click on "

man userdel " to see the Manual Page for this command.

Please click on "

man usermod " to see the Manual Page for this command.

Please click on "

man groupadd " to see the Manual Page for this command.

Please click on "

man groupdel " to see the Manual Page for this command.

Please click on "

man groupmod " to see the Manual Page for this command.


Previous Home Page Next


Contact us     |      About us     |      Term of use      |      Copyright © 2000-2025 MyWebUniversity.com ™