Friday, February 3, 2012

Users and Groups in Linux - 3

How to create user without group ?
Up to i searched and tried, we can't create user without group. We can only create a user with already created group.


How to create user with already created group ?
We can create a user with already created group with "-g" or "-G" option with "useradd" command.
Ex.
   useradd -g group1 user1
     //user1 will be create in group1 and group1 will be primary user of user1
   useradd -G group1 user1
     //user1 will be create in group1 and group1 will be secondary user of user1


How to create user without password ?
We can create a user without password by "passwd" command with "-d" option.
Ex.
   useradd test
   passwsd -d test


How to create user with more groups ?
When we create user, the primary group will be creat at same time or we want to mention group name with "-g" or "-G" option. We can mention multiple groups while create new user. And also we cam mention with "usermod" command for existing user.
Ex.
   useradd -g group1 -G group2,group3 test
     //"group1" is primary group for user "test" ; "group2" and "group3" are secondary groups for user "test".
   usermod -g group1 -G group2,group3 test
     //"group1" is primary group for user "test" ; "group2" and "group3" are secondary groups for user "test".


Is possible to change primary group of user ?
Yes we can change primary group of the user with usermod command.
Ex.
   usermod -g group1 user2


How to remove user from the group ?
We can remove user from the group with "gpasswd" command with "-d" option
Ex.
   gpasswd -d user1 group2
   ** If a user have the group as primary group, we can't remove the user from the group.


How to delete a user ?
We can delete user with "userdel" command, At the time of user creation, if we not mention home directory, it'll create a directory with user-name. We can use "-f" option for delete home directory of the user.
Ex.
   userdel -f user1
     //will delete user as well as user directory.


How to delete a group ?
We can delete a group, if it is not primary group of any user. We can use "groupdel" command for delete a group.
Ex.
   groupdel group1


How to make a user as root privileged ?
It's not recommenced for ever. But we can use sudo for make a user as like root (super user).


Is it possible to edit passwd / group file manually ? And it take affects in user and group ?
We can edit passwd , group files in /etc/. And it'll make changes in user, group and their permissions too.


Is it possible to create a user without user directory and how ?

Yeah we can create user without user(home) directory. The command "useradd" with "-M" will do it. We can login with it in terminal , it'll be as bash. and we can login with it as GUI. In gnome we can do only maintenance work it we know password of administrator/root. And be access some applications.

* Use man pages for more help.

No comments: