November 9, 2006

Unix Commands

useradd , userdel , usermod : Files : /etc/passwd, /etc/shadow and /etc/skel directory

Syntax : useradd [ -u uid ][ -g gid ][ -G gid [,gid,.. ]][ -d dir ][ -m ][ -s shell ][ -c comment ] loginname

-u uid – Sets the unique UID for the new user.
-g group – Specifies a predefined group's ID or name.
-G group – Defines the new user's secondary group memberships.
-d dir – Defines the full pathname for the user’s home directory.
-m – Creates the new home directory if it does not already exist.
-s shell – Defines the full pathname for the shell program to be
used as the user's login shell. If not defined, it defaults to /bin/sh.
–c comment – Typically used to specify the user’s full name and
location.
-o – Allows a UID to be duplicated.
-e expire – Sets an expiration date on the user account. Specifies
the date (mm/dd/yy) on which a user can no longer log in and
access the account. The account is locked.

$ useradd -u 100 -g other -d /export/home/username -m -s /bin/sh or /bin/csh or bin/ksh -c "new user account" username

**************************************************************************************
usermod [ -u uid [ -o ] ] [ -g group ] [ -G group [ , group . . . ] ] [-d dir ] [ -m ] ] [ -s shell ] [ -c comment ] [ -l newlogname ] [ -f inactive ] [ -e expire ] login

In general, the options for the usermod command function the same as for the useradd command, with the exception of the following

-l newlogname – Changes a user’s login name for the specified user account.
-m –Moves the user’s home directory to the new location specified with the -d option.

$usermod -d /export/home/newdirectory -m -l newuser username


**************************************************************************************
userdel [ -r ] login

-r – Removes the user's home directory from the local file system.This directory must exist.

$ userdel -r username : removes home directory and user from unix os
$userdel username : removes username only

**************************************************************************************
groupadd, groupmod, groupdel : Files : /etc/group

groupadd [ -g gid [ -o ] ] groupname

You can use the following options with the groupadd command:

-g gid – Assigns the group ID gid for the new group.
-o – Allows the gid to be duplicated.

$ groupadd -g 1000 groupname

**************************************************************************************
groupmod [ -g gid [ -o ]] [ -n name ] groupname

You can use the following options with the groupmod command:
-g gid – Specifies the new GID for the group.
-o – Allows the GID to be duplicated.
-n name – Specifies the new name for the group.

$groupmod -g 301 -n negroupname groupname

**************************************************************************************
groupdel groupname

$groupdel groupname

**************************************************************************************
System-Wide Initialization Files

The two main system initialization files are called /etc/profile and /etc/.login

The Bourne and Korn login shells look for and execute the system initialization file /etc/profile during login.
The C login shell looks for and executes the system initialization file/etc/.login during the login process.

Shell Variables:
The environment maintained by the shell includes variables that are defined by the login program, system initialization file, and the user
initialization files.
The shells support two types of variables:

Environment variables – Every shell program started receives its information about the user’s environment from these variables.
Local variables – This affects only the current shell. Any subshell started would not have knowledge of these variables.


**************************************************************************************

No comments: