User commands and files in linux


Hey,

in any linux distribution user is very important, whether you are root user or not it matters alot.

so lets go through some user commands.

User account information is stored in two different files.

File Contents :

/etc/passwd Each line identifies a user account.
Each line contains multiple fields, with each field
separated by a colon.

Shown below is a sample line from the passwd file:

bhushan23:x:501:501:bhushan:/home/bhushan23:/bin/bash

The fields within this line are as follows:
1.User account name.

2.Password. An x in the field indicates passwords are stored in the /etc/shadow file.

3.User ID number.

4.Primary group ID number, typically this number matches the UID number.

5.GECOS field, typically used for a description or the user’s full name.

6.Path to the home directory.

7.Path to the default shell.

 
/etc/shadow Like the /etc/passwd file, each line corresponds to a user account.

Each line consists of fields separated by colons.
Shown below is a sample entry:

bhushan23:$ab7Y56gu9bs:12567:0:99999:7:::

The fields within this line are as follows:
1.User account name.

2.Password. The $ in front of the password identifies the password as an encrypted entry.

3.Last change. The date of the most recent password change, measured in the number of days since 1 January 1970.

4.Minimum password age. The minimum number of days the user must wait before changing the password.

5.Maximum password age. The maximum number of days between password changes.

6.Password change warning. The number of days a user is warned before the password must be changed.

7.Grace logins. The number of days the user can log in without changing the password.

8.Disable time. The number of days since 1 January 1970, after which the account will be disabled.

Although it is possible to edit the passwd and shadow files manually to manage user accounts, doing so can disable your system. Instead, use a GUI utility or the following commands to manage user accounts.

useradd name : Create a user account. By default, when you create a user account, you create a home directory for that user with the same name under /home/username.

useradd bhushan
creates the bhushan user account

useradd -c text name : Add a description for the account in the GECOS field of /etc/passwd.

useradd -c “Bhushan Sonawane”  bhushan
creates the bhushan account with a comment

useradd -d path name : Assign an absolute pathname to a custom home directory location.

useradd -d /tmpusr/sales1 sales1
creates the sales1 user account with home directory located at /tmpusr/sales1

useradd -u ID name : Assign the user a custom UID. This is useful if you want to assign ownership of files and directories to a different user.

useradd -u 789 AA
creates the AA account with user ID 789

usermod name : Modify an existing user account. usermod uses the same switches as useradd.

usermod -c “b 23” bs
changes the comment field for user bs

usermod -l newname name : Rename a user account.When renaming the account, use the -d switch to rename the home directory, and use the -m switch to copy all files from the existing home directory to the new home directory.

usermod -l ab -d /home/ab -m linux

renames the linux account to ab, renames the home directory, and moves the old home directory contents to the new location.

usermod -s path name Modifies the default shell setting for the user account.

usermod -s /bin/bash AA points the shell for AA to/bin/bash userdel name Remove the user from the system.

userdel bs deletes the bs account while leaving the home directory on the system.

userdel -r name Remove the user and the user’s home directory. userdel -r bs removes both the account and the home directory

Note: If you ever edit the user database files manually, use the vipw command. This command locks the user files and opens them in vi for editing.

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s