There are several tasks involved in setting up a new user. The login name must be added to the system, the user must be assigned to a group, a home directory must be created for him, and a profile set up in his home directory. Only user root can create new users.
Different types of Unix and Linux installations have different methods of managing user accounts. Most installations have a GUI tool for this purpose. The GUI tool will generally create the user and his home directory, as well as assigning him to a group and giving him a password. The .profile in his home directory must be set up with a text editor, or copied from another user with similar settings.
If you prefer working from the command line, most installations support the useradd command. If you are using this command, you must either first create the user’s home directory, or use the appropriate switch to create it with useradd. The login name of the new user is given as an argument to the command. The useradd command has the following switches:
-d Specify home directory name
-g Specify either a group name or Group ID
-c Specify a comment
-f Specify the number of inactive days before the account is disabled
-e Expiry date in the form YYYY-MM-DD
-m Create home directory
-k Create skeleton entries in home directory
-G Specify list of supplementary groups
-s Specify the shell
-u Specify the UID
You must then make the new user the owner of his home directory, and, optionally, create a .profile script in this directory. Finally, the new user must be given a password.
To create a user with login name sam belonging to group student with a home directory named /usr/sam, the commands are:
mkdir /usr/sam
useradd –g student –d /usr/sam sam
chown sam /usr/sam
passwd sam
You will then be prompted for sam’s password, and asked to verify it.
Thursday, January 17, 2008
User and Group Maintenance Commands For Linux
Settings for existing users can be changed using the usermod command. This command uses the same switches as useradd, plus some additional ones. The additional switches include:
-l new_login_name Specify a new login name for this user. All other settings remain unchanged, and his home directory and files are not affected.
-L Lock the user. He will not be able to log in unless his login is unlocked.
-U Unlock a locked user
The userdel command is used to remove a user from the system. This removes entries from the /etc/passwd, /etc/shadow and /etc/group file relating to this user. He will therefore be unable to log in. If used with the –r switch, userdel will also remove the user’s home directory and mail entries.
The groupadd command is used to add new user groups to the system. If used with the –g switch, you can specify a group ID for this group. Otherwise, it will be allocated the next free group ID
The groupmod command makes changes to groups. Switches available are:
-g Specify a new group ID
-n Specify a new group name.
The passwd command can be used to change passwords or password-related settings. With no arguments or switches, it changes the password of the current user. For users other than root, this is the only option that is allowed. Given a user name as an argument, it changes the password for that user. The following switches can also be used:
-d Set this user to have no password
-S Display the status of this user
-m Set the minimum days before the password can be changed
-x Set the maximum days for which this password is valid
-W Specify a number of days before the password expires when the user will be warned
-l new_login_name Specify a new login name for this user. All other settings remain unchanged, and his home directory and files are not affected.
-L Lock the user. He will not be able to log in unless his login is unlocked.
-U Unlock a locked user
The userdel command is used to remove a user from the system. This removes entries from the /etc/passwd, /etc/shadow and /etc/group file relating to this user. He will therefore be unable to log in. If used with the –r switch, userdel will also remove the user’s home directory and mail entries.
The groupadd command is used to add new user groups to the system. If used with the –g switch, you can specify a group ID for this group. Otherwise, it will be allocated the next free group ID
The groupmod command makes changes to groups. Switches available are:
-g Specify a new group ID
-n Specify a new group name.
The passwd command can be used to change passwords or password-related settings. With no arguments or switches, it changes the password of the current user. For users other than root, this is the only option that is allowed. Given a user name as an argument, it changes the password for that user. The following switches can also be used:
-d Set this user to have no password
-S Display the status of this user
-m Set the minimum days before the password can be changed
-x Set the maximum days for which this password is valid
-W Specify a number of days before the password expires when the user will be warned
Linux Fundae: Recover lost root password
Try to boot linux in single user mode
For LiLo type ‘linux 1′ or ‘linux single’ at your LilLo boot prompt. If it asks for root password then this step will not work try next step.
For GRUB, at the boot screen press e, this will allow you to edit boot line. Append ’single’ to the boot line. Press enter then press b to boot with this modified boot line.
If you do not get the command prompt, follow the next step, otherwise you have the root file system mounted read only to you, you need to change this to rw. You can do this with mount -o remount,rw
Now you can change the root password by passwd command, or edit the /etc/shadow file, and remove encrypted password (by removing everything between first : and second : in the entry for root
If this method does not work. Do the following
For LiLo type ‘linux init=/bin/bash’ at LiLo boot prompt.
For GRUB press e. Append ‘init=/bin/bash’ to the boot line. Press enter and then press b.
Now you have the root file system mounted read only to you, you need to change this to rw. You can do this with mount -o remount,rw
Now you can change the root password by passwd command, or edit the /etc/shadow file, and remove encrypted password (by removing everything between first : and second : in the entry for root)
For LiLo type ‘linux 1′ or ‘linux single’ at your LilLo boot prompt. If it asks for root password then this step will not work try next step.
For GRUB, at the boot screen press e, this will allow you to edit boot line. Append ’single’ to the boot line. Press enter then press b to boot with this modified boot line.
If you do not get the command prompt, follow the next step, otherwise you have the root file system mounted read only to you, you need to change this to rw. You can do this with mount -o remount,rw
Now you can change the root password by passwd command, or edit the /etc/shadow file, and remove encrypted password (by removing everything between first : and second : in the entry for root
If this method does not work. Do the following
For LiLo type ‘linux init=/bin/bash’ at LiLo boot prompt.
For GRUB press e. Append ‘init=/bin/bash’ to the boot line. Press enter and then press b.
Now you have the root file system mounted read only to you, you need to change this to rw. You can do this with mount -o remount,rw
Now you can change the root password by passwd command, or edit the /etc/shadow file, and remove encrypted password (by removing everything between first : and second : in the entry for root)
Subscribe to:
Posts (Atom)