Saturday, November 5, 2011

How to install .tar.gz (tarball) files in Linux/Unix


tar.gz also known as tarball, an archive format for electronic data and software. Most Linux tarball contains a source code for software. If you are new to Linux I recommend using apt-get, rpm and yum command to install all binary packages.

Tarball are a group of files in one file. Tarball files have the extension .tar.gz, .tgz or .tar.bz2. Most open source software use tarball to distribute programs/source codes.

1: Uncompress tarball -

      To uncompress them, execute the following command(s) depending on the extension: 

$ tar zxf file.tar.gz
$ tar zxf file.tgz
$ tar jxf file.tar.bz2
$ tar jxf file.tbz2

 
Now change directory

$ ls
$ cd path-to-software/


2: Build and install software - 

                      Generally you need to type 3 commands as follows for building and compiling software…

# ./configure
# make
# make install


Where,
  • ./configure will configure the software to ensure your system has the necessary functionality and libraries to successfully compile the package
  • Make will compile all the source files into executable binaries.
  • Finally, make install will install the binaries and any supporting files into the appropriate locations.
3: Read INSTALL / README file - 
         
                 Each tarball comes with installation and build instructions. Open INSTALL or README file for more information:

$ vi INSTALL

Thursday, October 27, 2011

RPM (Red hat package manager)

What is RPM? –
           RPM is a powerful Package Manager for Red Hat, Sues and Fedora Linux. It can be used to build, install, query, verify, update, and remove/erase individual software packages. A Package consists of an archive of files, and package information, including name, version, and description:               

Install an RPM Package –
        RPM packages have file naming conventions like foo-2.0-4.i386.rpm, which include the package name (foo), version (2.0), release (4), and architecture (i386). Also notice that RPM understands FTP and HTTP protocols for installing and querying remote RPM files.

rpm –ivh foo-2.0-4.i386.rpm
rpm –i ftp://ftp.redhat.com/pub/redhat/RPMS/foo-1.0-1.i386.rpm
rpm –i http://oss.oracal.com/projects/firewire/dist/files/kernel-2.4.20-18.10.1.i386.rpm

Uninstall an RPM package –
          To uninstall an RPM package, we use the package name foo, not the name of the original package file foo-2.0-4.i386.rpm above.

rpm –e foo

Upgrade an RPM Package –
             To upgrade an RPM package, RPM automatically uninstalls the old version of the foo packages and installs the new package. It is safe to always use rpm –Uvh to install and upgrade packages, since it work fine even when there are no previous version of the packages installed! Also notice the RPM understands FTP and HTTP protocols for upgrading from remote RPM files.

rpm –Uvh foo-1.0-2.i386.rpm
rpm –Uvh ftp://ftp.redhat.com/pub/redhat/RPMS/ foo-1.0-2.i386.rpm
rpm –Uvh http://oss.oracle.com/projects/firewire/dist/files/kernal-2.4.2.18.10.1.i686.rpm

Query all installed Packages –
           Use RPM to print the name of all installed packages installed on your Linux system.

rpm –qa

Query an RPM Package –
             Querying an RPM package will print the package name, version, and release number of the package foo only if it is installed. Use this command to verify that a package is or is not installed on your Linux system.

rpm –q foo

Display Package Information –
            RPM can display package information including the package name, version, and description of the installed program. Use this command to get detailed information about the installed package.

rpm –qi foo

List Files in Installed Package –
         The following command will list all of files in an installed RPM package. It works only when the package is already installed on your Linux system.

rpm –ql foo

Which package owns a file? –
         Use the following command to determine which installed package a particular file belongs to – rpm –gf /usr/bin/mysql
  
For example:

# rpm –qf  /usr/bin/ mysql

Mysql-3.23.52-3


List Files in RPM File –
         Use RPM to query a (possibly) uninstalled RPM file with the use of the “-p” option. You can use the “-p” option to operate on an RPM file without actually installing anything. This command lists all files in an RPM file you have in the current directory. Also note that RPM can query remote files through the FTP and HTTP protocols.

rpm –qpl kernel-2.4.20-18.10.1.i686.rpm
rpm –qpl ftp://ftp.redhat.com/pub/redhat/RPMS/foo-1.0.1.i386.rpm
rpm –qpl http://oss.oracle.com/projects/firewire/dist/files/kernal-2.4.20-18.10.1.i686.rpm

Verify an installed Package –
           Use RPM to list all files that do not pass the verify tests (done on size, MD5 signature, etc)

rpm –verify mysql

Where a file does not pass, the output is listed using the following codes that signify what failed:

S       File size
M      mode (includes permission and file type)
5        MD% sum
L       symlink
D       Device
U       User
G       group
T       mtime

Take for example the following:

# rpm –verify mysql
S.5….T c /etc/my.cnf

This example indicates that file /etc/my.cnf failed on:

File size
MD5 Sum
Modified Time

However, the “c” tells us this is a configuration file so that explains the changes. It should still be looked at to determine what the changes were.

Check an RPM signature Package –
                                        RPM can be used to check the PGP signature of specified packages to ensure its integrity and origin. Always use this command first before installing a new RPM package on your system. Also, GnuPG or Pgp software must be already installed on your system before you can use this command.

rpm –checking foo

Wednesday, October 19, 2011

Text Editor - (VI)


#vi - It is a text editor in Linux. We use vi, either to create a new file or to modify an old file. It should be used with a file name following it, which is as follows:

# vi /home/ajay/file1

if it is a new file, we will see something as under.
~
~
~
~
~
“/home/ajay/file1” [New File]



Command mode – 
         It is the default mode. It is used to search text, delete characters, words or lines or scroll within the text. We can come back to the command mode from text mode by using escape (Esc) key. We can use this mode to enable line numbering also, which is as follows:
: set nu
Deleting text – To delete the text in vi, we have three commands associated with the current location of cursor.

dd - To delete the whole line
dw - to delete current word
x - to delete current character
yy - to copy the whole lines
pp - to paste the whole copied line


Searching text
  Searching of text can be done easily with forward slash. For example if we want to search the word India, we can type the following:

/India

it will highlight the first place of the found word. To go to the next instance just press an other commands used within command mode are:

Saving text: w
Quitting after Saving: q
Saving and Quitting: wq
Forcefully quitting without Saving: q!
Forcefully quitting with saving: wq!

K - up the file line
J - down the file contents
W - for starting the word
E- for editing the word
Back - delete only insert mode
OD - delete the full line
U - undo the file (without insert)
YY - copy the all line (selected line)
PP - paste the all line
: set NU - number of lining (without insert)
Small p - up the paste the line
Copy p - down to paste line  

Monday, October 17, 2011

User & Group Management in Linux


What is a user account? –
                   A user account is a collection of information that tells Windows what files and folders you can access, what changes you can make to the computer, and your personal preferences, such as your desktop background or color theme. User accounts make it so that you can share a computer with several people, but still have your own files and settings. Each person accesses their user account with a user name and password.
There are three different kinds of accounts:
1- Standard
2- Administrator
3- Guest
Each account type gives the user a different level of control over the computer. The standard account is the account to use for everyday computing. The administrator account provides the most control over the computer, and should only be used when necessary. The guest account is primarily for people who need temporary access to the computer.
A user account allows one to authenticate to system services. It also generally provides one with the opportunity to be authorized to access them. However, authentication does not automatically imply authorization. Once the user has logged on, the operating system will often use an identifier such as an integer to refer to them, rather than their username. On UNIX systems this is called the user identifier or user id.
Computer systems are divided into two groups based on what kind of users they have:
  • single-user systems do not have a concept of several user accounts
  • Multi-user systems have such a concept, and require users to identify themselves before using the system.
What is a group? –
                In personal or business computing, a user group is a set of people who have similar interests, goals, or concerns. The members have regular meetings where they can share their ideas.
Ideally, the members of a user group live in the same geographic area, so they can get together in person. However, some user groups have members distributed throughout the world, and they meet using Internet chat rooms, message boards, or mailing lists. Members may also correspond by telephone and e-mail on a one-to-one basis. User groups often have Web sites that each member can visit on a regular basis to stay informed.
A user group may be devoted to a particular technology, application, or corporation. For example, a digital-photography user group might discuss the assets and limitations of various digital cameras and image-processing programs. A user group devoted to wireless Internet would share their experiences with the various providers of that technology. Some user groups are involved only with the products of a particular corporation. When devoted to a narrow range of products or ideas, the user group is sometimes called a special interest group.

Benefits of Linux User Management – 

                Linux User Management and Directory work together to simplify administration and provide users with access to network resources.

Administrator Benefits –
                Using LUM and Directory to manage user login information eliminates the need to create local users in the /etc/passwd and /etc/shadow files on each Linux computer. It simplifies user account management by consolidating user accounts into a central point of administration. Administrators can use Directory tools and technologies to manage access to Linux resources on the network. After authenticating, users have the rights and privileges as specified in Directory. These are the same rights and privileges that would typically need to be stored in a local account or redirected to other authentication methods, such as NIS. The user account information stored in Directory lets users’ access file and printer resources on the network.

User Benefits –
                 Users can log in to Linux computers using access methods such as login, ftp, ssh, su, rsh, rlogin, xdm (KDE*), and gdm (GNOME). They need only enter their familiar directory username and password. There's no need to remember a full context—Linux User Management searches out the correct user in directory. Users can log in once, using a single username and password, and have seamless access to all their network resources regardless of platform.

Understanding Linux User Accounts – 

                    Setting up and using directory to manage Linux access requires you to understand how the Linux operating system manages user logins. Users who want to log in to a Linux computer must have an existing user account, which consists of properties that allow a user to access files and folders stored on the computer. This account information can be created and stored on the computer itself or on another computer on the network. Accounts stored on the computer are called local user accounts. Accounts stored in directory are called directory user accounts, regardless of whether they are stored on the same or another computer. A typical account used to log in to a Linux computer consists of the following information:

1- Username and user ID (UID)
2- Password
3- Primary group name and group ID (GID)
4- Secondary group names and group IDs
5- Location of home directory
6- Preferred shell

When a local user account is created, Linux records the user-login information and stores the values in the etc/passwd file on the computer itself. The passwd file can be viewed and edited with any text editor. Each user account has an entry recorded in the following format:
Username:password:UID:GID:name:home directory:shell

Username and User ID
                    The username and user ID (UID) identify the user on the system. When created, a user account is given a name and assigned a UID from a predetermined range of numbers. The UID must be a positive number and is normally above 500 for user accounts. System accounts typically have numbers below 100.

Password –
               Each user account has its own password which is encrypted and stored on the computer itself or on another computer on the network. Local passwords are stored in the     /etc/passwd file or /etc/ shadow file. When the user logs in by entering a username and password, Linux takes the entered password, encrypts it, and then compares the encrypted value to the value of the password stored in the user account. If the entered value is the same as the value stored in the password field on the computer, the user is granted access. Administrators often use the /etc/passwd file to hold user account information but store the encrypted password in the /etc/shadow file; if using this method, the passwd file entry has an x in the password field.

Primary Group Name and Group ID –
                   Groups are used to administer and organize user accounts. When rights and permissions are assigned to a group, all user accounts that are part of the group receive the same rights and permissions. The group has a unique name and identification number (GID). The primary GID and group name are stored as entries in the /etc/passwd file on the computer itself or in directory. Each user has a designated primary (or default) group and can also belong to additional groups called secondary groups. When users create files or launch programs, those files and programs are associated with one group as the owner. A user can access files and programs if he is a member of the group with permissions to allow access. The group can be his primary or any of his secondary groups.

Secondary Group Names and Group IDs –
                 Although not strictly part of the user account, secondary groups are also a part of the user login experience. Groups and GIDs are used to manage rights and permissions to other files and folders. Secondary groups for each user are listed as entries in /etc/group on the computer itself.

Home Directory –
                  The home directory is a folder used to store a user’s personal documents. In addition, it offers a place to store configuration files unique to the user. Therefore, a user can log in and find his environment with the same settings as he had before, even if another user has used the computer. Typically, most computers have all home directories at /home, and then individual directories listed by login name (for example, /home/jsmith). The root user’s home directory is an exception. It is traditionally located at / or /root. Placing home directories under /home is not required—but it does make organizational sense. Some administrators divide the /home directory by function or department and then subdivide the /home directory with users in that department (for example, /home/engineering/jsmith).

User Accounts in directory –
                    User accounts residing on the Linux computer are said to be local user accounts and are stored as entries in the /etc/passwd file. User accounts in directory are represented by User objects stored in the directory tree. A directory User object has a rich set of properties and fields to hold user-login properties. When a directory User object is extended to hold Linux user-login properties, it is said to be LUM enabled or enabled for Linux. When enabled for Linux, a user can simply access the Linux computer (using Telnet, SSH, or other supported method) and enter his username and password. The access request is redirected to find the appropriate username and login information stored in directory. When extended for Linux, the directory User object holds Linux-related properties, such as user ID, primary group ID, primary group name, location of home directory, and preferred shell.

Group Objects in directory –
                      When a group is enabled for Linux, the group ID is stored as a property of a Linux/UNIX Workstation object. When the user attempts to log in to a Linux computer, he only needs to enter his username and password—no context is required. The Linux computer checks its corresponding Linux/UNIX Workstation object in directory for the list of groups approved to log in. Each approved group is searched for the username of the user requesting access. When the first matching username is found, the login is allowed using the UID, GID, password, and other login information stored in directory. If the username is not found in any of the groups, the login is not allowed.

User in Linux –
               Internally Linux users manage with their Identity. The use root has the UID 0 and other system users have (bin, IP etc) home use ids from 1 to 499 and the other users have ID about the 500 or more.

Following commands are use to manage a user account –

#useradd or adduser –

                 System administration command. Create new user accounts or update default account information. Unless invoked with the -D option, user must be given. useradd will create new entries in system files. Home directories and initial files may also be created as needed.
-c (comment)
                    Comment field.

-d (dir) –  
              Home directory. The default is to use user as the directory name under the home directory specified with the


-e (date)
                            ---------- Account expiration date. Use the format MM/DD/YYYY. Two-digit year fields are also accepted. The value is stored as the number of days since January 1, 1970. This option requires the use of shadow passwords.

-f (days)
         Permanently disable account this many days after the password has expired. A value of -1 disables this feature. This option requires the use of shadow passwords.

-g (group) –
            Initial group name or ID number. If a different default group has not been specified using the -D option, the default group is 1.

-G (groups)
      Supplementary groups given by name or number in a comma-separated list with no whitespace.

-k (dir) –
           Copy default files to the user's home directory. Meaningful only when used with the -m option. Default files are copied from /etc/skel/ unless an alternate dir is specified.

-m -
      Make user's home directory if it does not exist. The default is not to make the home directory.

-M –  
         Do not create a home directory for the user, even if the system default in /etc/login.defs is to create one.

-n
         Red Hat-specific option. Turn off the Red Hat default that creates a group with the same name as the username and puts the user in that group.

-o
          Override. Accept a non unique UID with the -u option. (Probably a bad idea.)

-p passwd
           The encrypted password, as returned by crypt.


-r
           Red Hat-specific option. Create a system account with a non-expiring password and a UID lower than the minimum defined in /etc/login.defs. Do not create a home directory for the account unless -m is also specified.

-s shell - 
           Login shell.

-u uid
           Numerical user ID. The value must be unique unless the -o option is used. The default value is the smallest ID value greater than 99 and greater than every other uid.

-D [options] –
             Set or display defaults. If options are specified, set them. If no options are specified, display current defaults. The options are:

-b dir
             Home directory prefix to be used in creating home directories. If the -d option is not used when creating an account; the user name will be appended to dir.

-e date
          Expire date. Requires the use of shadow passwords.

-f days
                Number of days after a password expires to disable an account. Requires the use of shadow passwords.

-g group
                Initial group name or ID number.
-s shell
                      Default login shell.

Some use full commands –
1-   #adduser or #useradd –
                                  This command is used for creating a new user account in linux.
2-   #usermod –
                   This command is used to change the permission of any user.
3-   #Userdel –
              This is used for delete the user account.

There is a number of ways to creating a user and managing the user account in RHEL -5 or other version of linux.


1- Click Applications then select System Settings and click Users and Groups. This will launch the User Manager window.


2- In the User Manager window, click Add User. This will show the Create New User window.


3- In the Create New User window, fill in the User Name, Full Name, Password and Confirm Password. Click Ok when you’re done.


4- That’s it; you have just created a new user. To remove a user, select the user you want to remove and click Delete.

     You can also do this from the command line, below are the equivalent commands. You need to have root level access to use the commands below.

1- usr/sbin/useradd [options] login_name
---creates a new user
2- usr/sbin/usermod [options] login_name
---modifies a user’s attributes
3- usr/sbin/userdel [options] login_name
---deletes the specified user. Use the
-r option to automatically remove the user’s home directory and mail spool.
4- usr/bin/passwd login_name
---sets the password for the specified user
5- usr/sbin/groupadd [options] group_name
---creates a new group
6- usr/sbin/groupmod [options] group_name
---modifies a group’s attributes
7- usr/sbin/groupdel group_name
---deletes the specified group

How to Setup User Password Expiration in RHEL

                   Ideally, passwords should be changed regularly. This article describes how to setup password expiration using the User Manager application in Red Hat Enterprise Linux 5.

1- Click Applications then select System Settings and click Users and Groups. This will launch the User Manager window.


2- Select the user you wish to configure and click Properties.


3- in the User Properties windows, click the Password Info tab.


4- Check the Enable Password Expiration checkbox to enable password expiration. The list below describes the available settings.
  • Days before change allowed
                            Number of days from the last password change to allow another password change.
  • Days before change required
                           Number of days from the last password change to require another password change.
  • Days warning before change
                           Number of days before the expiry of the password to notify the user.
  • Days before account inactive
                             Number of inactive days after the expiry of the password to deactivate the account. 0 means do not deactivate.

You can also do this from the command line, below are the equivalent commands.

chage login_name
modifies the password expiry information of the specified login name. You need root access to use this command.


chage -l login_name
shows the password expiry information of the specified login name

chage   displays the help information

You can notify the users with expiring password via email using the checkpwexpire script. Copy the script into the /etc/cron.daily and give it execute permission so it will automatically run every day.

Create a user by file editing –

#vi   /etc/passwd
          This file keeps the information of user name
            
#vi   /etc/group
         This file keeps the information of every user
            
#vi   /etc/shadow
         This file keeps the information of user password
           
#vi   /etc/gshadow
        This file keeps the information of group password to access resources.

Create user through the files. It will start from root-

#vi   /etc/passwd

ajay:x:516:1002::/home/ajay:/bin/bash

 
Ajay                 :        username
X                     :        represent user password
516                  :        user identity number (UID)
1002                :         group identity number (GID)
::                      :         extra information
/home/ajay       :        home directory of this user
:/bin/bash         :        shell


-- This user will also use graphic home. We will have to copy some file in ajay.

#cp   /etc/skel/   .kde   /home/ajay
#cp   /etc/skel/ * /home/ajay

-- We want to give some right as root to a user.
#vi   /etc/passwd

Ajay:x:516:1002::/home/ajay:/bin/bash
Ajay:x:0:0::/home/ajay:/bin/bash