Tuesday, April 16, 2013

Change Properties of Existing user                                         Groupadd/Groupdel command

Useradd command is very useful in unix to add user or update the user’s information or user’s home directory, comment etc. Almost all options are same for useradd command in solaris/Linux/Ubuntu. There are many uses of useradd command. We will understand the useradd command with examples:

Add user with home directory:

If you are not specifying the home directory while creating user, then system will create default base directory for that user. The base directory is concatenated with account name to define home directory. If you want to specify different home directory then we need to specify home dir(-d). When we use –d option then no use of –b option.
[root@rhel home]# useradd -d /home/test test
[root@rhel home]#
[root@rhel home]# ls -lrta /home/test
total 28
-rw-r--r--. 1 test test  124 Jun 22  2010 .bashrc
-rw-r--r--. 1 test test  176 Jun 22  2010 .bash_profile
-rw-r--r--. 1 test test   18 Jun 22  2010 .bash_logout
drwxr-xr-x. 2 test test 4096 Jul 14  2010 .gnome2
drwxr-xr-x. 4 test test 4096 Mar 20 18:06 .mozilla
drwxr-xr-x. 4 root root 4096 Apr 12 22:59 ..
drwx------. 4 test test 4096 Apr 12 22:59 .
[root@rhel home]#

Add user with comment, home directory:

If we want to give comment to identify the user then we can use –c option and for home directory –d option.
[root@rhel home]#
[root@rhel home]# useradd -c "linux concepts and commands" -d /home/test2 test2
[root@rhel home]# cat /etc/passwd | grep linux
test2:x:502:502:linux concepts and commands:/home/test2:/bin/bash
[root@rhel home]#

Disable user automatic after some period:

We can disable added user automatically after some period. For this purpose, we need to specify date on which the user account will disable. The date should have to specify in YYYY-MM-DD format. If this parameter is not specified while creating user then system will  consider default expiry date (/etc/default/useradd) specified in this file. If you want to extend the expiry date of user then you can do it by usermod command.
[root@rhel home]# useradd -e 2013-04-17 -d /home/test3 test3
[root@rhel home]#
[root@rhel home]# cat /etc/passwd | grep test3
test3:x:503:503::/home/test3:/bin/bash
[root@rhel home]#

Add user in existing group:

We can add user in existing group by specifying group name while creating user first time. We can change the group by usermod command after creation of user as well. Or we can insert user in multiple groups as well. If group is not already exist then create it by groupadd command.
[root@rhel home]#
[root@rhel home]# useradd -d /home/test4 -c "Linux Concepts" -e 2013-04-18 -g test3 test4
[root@rhel home]# cat /etc/passwd | grep test4
test4:x:504:503:Linux Concepts:/home/test4:/bin/bash
[root@rhel home]# cat /etc/group | grep 503
test3:x:503:
[root@rhel home]#

We can change any parameter of user after creation for this we need to use usermod command. To delete the user permanently userdel command is available for this purpose.
Posted by Machindra Dharmadhikari On 4/16/2013 11:14:00 PM 1 comment

1 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner