useradd command syntax
useradd [options] {username}Depending on command line options, the useradd command will update system files (/etc/passwd and /etc/shadow file with password) and may also create the new user's home directory and copy initial files.
Linux add a new user called rakhi
Type the command as follows:useradd amitSet a password for rakhi:
passwd amitWithout password user account will be in locked status. To unlock the account, you need to use above passwd command. Use passwd command to assign a password and set password aging guidelines.
Set account disable date
You can set date for the account to be disabled in the format YYYY-MM-DD with -e option while creating account itself:useradd -e {yyyy-mm-dd} {username}
 useradd -e 2008-12-31 jerrySet default password expiry
The -f {days} option set number of days after the password expires until the account is disabled. (If 0 is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not be disabled after the password expires.)useradd -f {days} {username}
 useradd -e 2009-12-31 -f 30 jerryHow to create a new group in Linux using groupadd command
The groupadd command can be used in Linux to add user groups to the system.
 The basic syntax of Linux groupadd command is  groupadd 
<groupname>. If no command-line options are used, the group is  
created with the next available Group ID number (GID) above 499. To 
specify a GID, use the  groupadd -g <gid> <group-name> 
command.
[root@RHEL2 ~]# groupadd  engineering 
Howto: Linux Add User To Group
useradd Example - Add A New User To Secondary Group
You need to the useradd command to add new users to existing group (or create a new group and then add user). If group does not exist, create it. The syntax is as follows:useradd -G {group-name} usernameIn this example, create a new user called vivek and add it to group called developers. First login as a root user (make sure group developers exists), enter:
# grep developers /etc/groupOutput:
developers:x:1124:If you do not see any output then you need to add group developers using groupadd command:
# groupadd developersNext, add a user called vivek to group developers:
# useradd -G developers vivekSetup password for user vivek:
# passwd vivekEnsure that user added properly to group developers:
# id vivekOutput:uid=1122(vivek) gid=1125(vivek) groups=1125(vivek),1124(developers)Please note that capital G (-G) option add user to a list of supplementary groups. Each group is separated from the next by a comma, with no intervening whitespace. For example, add user jerry to groups admins, ftp, www, and developers, enter:
# useradd -G admins,ftp,www,developers jerryusermod example - Add a existing user to existing group
Add existing user tony to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option :# usermod -a -G ftp tonyChange existing user tony primary group to www:
# usermod -g www tonyLinux: Delete / Remove User Account
userdel userName
userdel Example
To remove the user vivek account from the local system / server / workstation, enter:# userdel vivekTo remove the user's home directory pass the -r option to userdel, enter:
# userdel -r vivekThe above command will remove all files along with the home directory itself and the user's mail spool. Please note that files located in other file systems will have to be searched for and deleted manually.
Here are a couple of useful commands that may help you to manipulate users and group in a Linux environment.
Groups are useful when to want multiple users to share some areas among them, while users not in the group won’t have an access to the shared space.
It helps in building a hierarchy in a Linux system.
When you create a new user, a new group is also created with him.
useradd $USERYou can use the command “id” to check the groups of a user.
Here a new user hoge is created.
root@boheme:/etc# id hoge
uid=1003(hoge) gid=1004(hoge) =1004(hoge)
root@boheme:/etc# useradd hoge
root@boheme:/etc# cat /etc/group | grep hoge
hoge:x:1004:In the case of adding a new user immediately in a primary group, you can use:
useradd -g $GROUP $USERHere is an example:
root@boheme:/etc# groupadd foo
root@boheme:/etc# useradd -g foo hoge
root@boheme:/etc# id hoge
uid=1003(hoge) gid=1003(foo) =1003(foo)So here user hoge has been created and has foo as primary group.
You can also add secondary groups to a user, with the option “-G”
usermod -G $GROUP $USER Here is an example:
root@boheme:/etc# groupadd foo2
root@boheme:/etc# usermod -G foo2 hoge
root@boheme:/etc# id hoge
uid=1003(hoge) gid=1003(foo) 所属グループ=1003(foo),1004(foo2)Here, user hoge has been added to the group foo2, and his primary group has not changed.
You can also remove a use from secondary group with:
 gpasswd -d $USER $GROUPHow to add and remove groups in Linux
This is one of the key question many new Linux admin faces. The answer is use
groupadd command to create a new group. For example add a new group called sales:
To delete a group use groupdel command. For example delete a group called ftpusers:Code:groupadd sales
Code:groupdel ftpusers
0 comments:
Post a Comment