Friday, 8 July 2011

Linux - Create New User - adduser

If you wish to create a new user on a Linux/UNIX environment then you will need to use the useradd command. This will add the new user to the /etc/passwd file, create their home directory, add them to the relevant groups in /etc/group, and specify their shell where necessary and details provided.

Useradd Example

If we wished to create user krobbe on the new system I would issue the following command. For completeness it contains all groups I require, a comment for maintenance, the uid, and a flag to force home directory creation if not already created.
useradd -c "Kerri Robberts, Linedata" -m -d /home/krobbe -g 300 -G 700,901,902,951 -s /usr/bin/ksh -u 1040 krobbe

Useradd flags

useradd
This is the command for adding a user
-c "<comment>"
This flag allows you to enter a comment to be added into the /etc/passwd file.
-m -d <home directory>
The -m flag forces the system to create the home directory for the user specified using the -d flag.
-g <groupid>
The -g flag specifies the users initial group. This can either be specified by groupid, or by fullname.
-s <shell binary location>
The -s flag specifies the users default shell. This is normally something like /usr/bin/ksh
-u <userid>
The -u flag specifies the userid for the new user. The default is the smallest number after 99 that hasn't already been used and greater than the highest number used for other users. Values between 0 and 99 are typically reserved for system users.

NB. The name of the user to be added goes at the end of the entire command.

No comments:

Post a Comment

Please feel free to leave a comment