Thursday, March 22, 2018

XFS


Few Points on XFS:


  • Default file system on RHEL 7
  • XFS is a highly-scalable 64-bit jounraling file system that can used on a single host.
  • It supports metadata journaling which means the crash recovery is quicker.
  • Even though we can grow an XFS file system online, it is not possible to shrink.
  • No file system check at boot time
  • Can go upto 500TB filesytems and 50TB files
  • Less cpu intensive

 

Some commands...

To create an XFS file system on a newly created logical volume:
# mkfs.xfs /dev/vgxx/lvxx

To grow an XFS file system:
# xfs_growfs /mount-point -D size

To label an xfs file system:
# xfs_admin -L "label" /dev/vgxx/lvxx

To show the label of an xfs file system:
# xfs_admin -l /dev/vgxx/lvxx

To repair an XFS file system (make sure the file system is unmounted before you run the below command):
# xfs_repair /dev/vgxx/lvxx

In case of dirty log, use the following command to clear the log.
# xfs_repair -L /dev/vgxx/lvxx

To freeze an xfs file system:
# xfs_freeze -f /mount/point

To unfreeze an XFS file system:
# xfs_freeze -u /mount/point

To show the file system information:
# xfs_info /dev/vgxx/lvxx

To do a full backup a xfs file system on a tape:
# xfsdump -l 0 -f /dev/st1 /data

Here "-l" means the level of backup. 0 always mean a full backup. You may replace it with the numbers from 1 to 9 which means an incremental backup.

To do a labelled full backup:
# xfsdump -l 0 -L "/data backup on 3rd March 2018" -f /dev/st1 /data

To list the backup labels on a tape:
# xfsrestore -I -f /dev/st0

To restore a xfs backup using a label a different location:
# xfsrestore -L "/data backup on 3rd March 2018" -f /dev/st1 /data-temp

To display quota:
# xfs_quota -x -c 'report -h' /data

To set the soft and hard data(block) quota (in MB) for a user:
# xfs_quota -x -c 'limit bsoft=500m bhard=900 mark' /data/

To set soft and hard inode quota for a group:
# xfs_quota -x -c 'limit -g isoft=1000 ihard=1500 dba' /data/

Monday, December 19, 2016

Managing Swap space in Red Hat Linux

1. To extend a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Extend the logical volume by 1GB
# lvm lvresize /dev/VolGroup00/LogVol05 -L +1G

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


2. To reduce a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Reduce the logical volume by 512MB
# lvm lvresize /dev/VolGroup00/LogVol05 -L -512M

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


3. To list all the configured swap devices:

# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/mapper/VolGroup00-LogVol05         partition       6062072 2180    -1


4. To list the total/used/free swap space:

# free -tm
             total       used       free     shared    buffers     cached
Mem:          7983       7918         65          0        585       4943
-/+ buffers/cache:       2389       5594
Swap:         5919          2       5917
Total:       13903       7920       5982


5. To create a swap file of size 100MB :

# dd if=/dev/zero of=/swap1 bs=1024 count= 102400
# chmod 0600 /swap1
# mkswap /swap1
# swapon /swap1

Finally add the below entry in /etc/fstab so that it enables on every boot.

/swap1          swap            swap    defaults        0 0


6. To enable swap space on a file :

# swapon -v /swap1


7. To disable swap space on a file :

# swapoff -v /swap1

Software RAID in Red Hat Linux

To create a linear RAID array:

# mdadm --create --verbose /dev/md0 --level=linear --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To create a striped RAID array (RAID-0):

# mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To create a mirrored RAID array (RAID-1):

# mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To start a RAID Array:

# mdadm --assemble /dev/md0 /dev/sdb /dev/sdc /dev/sdd

                                                    OR

# mdadm --scan --assemble --uuid=a26bf396:31389f83:0df1722d:f404fe4c


To list all software raid arrays and their component devices:

# cat /proc/mdstat
Personalities : [linear]
md0 : active linear sdd[0]
      10485752 blocks super 1.2 0k rounding

md1 : active linear sde[0]
      52428792 blocks super 1.2 0k rounding

unused devices:




 

To query a software raid array :

# mdadm --query /dev/md1
/dev/md1: 129.100GiB linear 1 devices, 0 spares. Use mdadm --detail for more detail.


To list details of a RAID array:

# mdadm --detail /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Thu Dec 11 09:32:37 2011
     Raid Level : linear
     Array Size : 52428792 (50.00 GiB 53.69 GB)
   Raid Devices : 1
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Thu Dec 11 09:32:37 2011
          State : clean
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

       Rounding : 0K

           Name : server123:1  (local to host server123)
           UUID : c5804771:253326af:e062f685:cab35fed
         Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc


To examine a RAID array:

# mdadm --examine /dev/md0


To add a raid disk device and extend a linear software raid array :

# mdadm --detail /dev/md3 | tail -n 3
    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sdc
       1       8       17        1      active sync   /dev/sdd

# mdadm --grow /dev/md3 --add /dev/sde


To remove a RAID array:

# mdadm --stop /dev/md3
# mdadm --remove /dev/md3
# mdadm --zero-superblock /dev/sdc /dev/sdd

Friday, September 9, 2016

MySQL - Part 1

Packages required:
mysql - contains client programs, configuration files and documentation
mysql-server - contains server daemon, startup script and various administrative files and directories
mysql-devel - contains libraries and header files for development purpose

Optional packages:
php-mysql - contains a shared library to allow PHP applications access MySQL databases
mod_auth_mysql - contains tools to authorize Apache Web server access from data in a MySQL database
perl-DBD-MySQL - contains a perl interface to MySQL databases
mysql-bench - contains scripts for benchmarking MySQL databases
MySQL-python - contains a Python interface to MySQL
qt-MySQL - MySQL drivers for QT SQL classes
mysql-administrator - GUI based tool to manage MySQL databases


Server daemon: mysqld

Startup script: /etc/init.d/mysqld

Configuration file: /etc/my.cnf

Log file: /var/log/mqsqld.log

Few Tips for beginners:

1. To set password for root user in MySQL (this is different from the root password in OS):

# mysqladmin -u root password mypasswd

You need to mention this password whenever you run a mysql command.
To make it easy, you can add the password to the file /root/.my.cnf and change the permission to 600

Here is a sample content of /root/.my.cnf

[client]
mypassword


2. What happens when you start MySQL server for the first time:

It creates tables for 2 databases mysql and test. And the information is stored in the /var/lib/mysql/mysql and /var/lib/mysql/test directories, respectively.

3. How to start mqsql command ?

$ mysql -u root
Enter password: *********

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13

Server version: 5.0.37 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer

mysql>

If you want to connect to mysql on a remote server, use -h hostname or ipaddress to the end of the command.


Some mysql interface commands :

1. Shows the version, connected database, remote or local connection,etc...

mysql> status

2. To create a new database :

mysql> CREATE DATABASE mydb;

You can also create a database using mysqladmin command as below

# mysqladmin -u root -p create

3. To list all the databases on your mysql server :

mysql> SHOW DATABASES;

4. Before working on a database, make it as your current database.

mysql> USE mydb;

5. To create a table:

mysql> CREATE TABLE employee (
-> name      varchar(20)    not null,
-> empid       varchar(6)    not null,
-> phonenumber     varchar(10)    not null,
-> city           varchar(20)    not null,
-> state          varchar(20)    not null,
-> zipcode        varchar(10)    not null
-> );

6. To show all tables in your current database :

mysql> SHOW tables;

7. To display the format of the "employee" table :

mysql> DESCRIBE employee;

8. To add data to the table "employee" :

mysql> INSERT INTO employee
-> VALUES ('Mike','112233','2349871239',
-> 'Philadelphia','PA','11227');

9. To list the contents of the table:

mysql> SELECT * FROM employee;

10. To load data from a text file into a table:

$ mysql -u root -p
Enter password: *******
mysql> USE mydb
Database changed
mysql> LOAD DATA INFILE "/tmp/emp.txt" INTO TABLE employee;
Query OK, 5 rows affected (0.04 sec)
Records: 5  Deleted: 0 Skipped: 0 Warnings: 0

Wednesday, January 27, 2016

How to integrate Red Hat Satellite with VMWare (ESX)



You can integrate Red Hat Satellite with VMWare ESX Hypervisor so that you can just use one license "Red Hat Enterprise Linux for Virtual Datacenters, Standard" per ESX.

Here is the procedure to make your satellite talk to ESX hypervisor to retrive the UUIDs


1. Register a VMWare based Linux server on Satellite

2. Install virt-who package

# yum install virt-who

3. Add the following lines onto /etc/sysconfig/virt-who


4. Enable and restart virt-who service

# chconfig virt-who on

# service virt-who restart

5. Now virt-who will populate all your hypervisors on RedHat satellite webUI.

6. Go to Content > Content host. Here you will find some systems with UUID. These are all hypervisors reported by your virt-who service.

7. Select a hypervisor > Subscription > Add > Select virtual datacenter subscription. > attach.
Follow this step for all hypervisors available on web UI.

8. Now on your virt-who server execute the following command to list out the hypervisors inherited virtual datacenter subscription.
This subscription contains the pool id. Note down this pool id.

# subscription-manager list --available

9. Now subscribe your system

# subscription-manager subscribe --pool=

Friday, December 18, 2015

Daemons used in Satellite 6.1

Here are some daemons used in Satellite 6.1.

MongoDB - Database used by Pulp.

To Manage on RHEL6:
# chkconfig mongod on
# service mongod start

To Manage on RHEL7:
# systemctl enable mongod
# systemctl start mongod


Qpid - Message bus used by Pulp.

To Manage on RHEL6:
# chkconfig qpidd on
# service qpidd start

To Manage on RHEL7:
# systemctl enable qpidd
# systemctl start qpidd


Apache - Web Server

To Manage on RHEL6:
# chkconfig httpd on
# service httpd start

To Manage on RHEL7:
# systemctl enable httpd
# systemctl start httpd


Pulp Workers -

To Manage on RHEL6:
# chkconfig pulp_workers on
# service pulp_workers start

To Manage on RHEL7:
# systemctl enable pulp_workers
# systemctl start pulp_workers


Pulp Celerybeat -  This process performs a job similar to a cron daemon for Pulp.

Config File:  /etc/default/pulp_celerybeat

To Manage on RHEL6:
# chkconfig pulp_celerybeat on
# service pulp_celerybeat start

To Manage on RHEL7:
# systemctl enable pulp_celerybeat
# systemctl start pulp_celerybeat


Pulp Resource Manager  - This process acts as a task router.

Config File: /etc/default/pulp_resource_manager

To Manage on RHEL6:
# chkconfig pulp_resource_manager on
# service pulp_resource_manager start

To Manage on RHEL7:
# systemctl enable pulp_resource_manager
# systemctl start pulp_resource_manager

Scan a recently added virtual disk in a VMWare based Linux server

1. Take an output of the currently available disks

# fdisk -l


2. Scan for the new disk

# echo "- - -" > /sys/class/scsi_host/host0/scan


3. List the available disk to find out the name of newly created disk

# fdisk -l

4. View the messages file for confirmation

# tail -f /var/log/messages

How to do release update on Red Hat Linux ?

 Following procedure guides you on how to update a Red Hat Linux server from RHEL 6.3 to 6.4.

1. Mount the file RHEL6.4-Server-20130130.0-x86_64-DVD1.iso on a directory.

# mount -o loop RHEL6.4-Server-20130130.0-x86_64-DVD1.iso /media/rhel6/

2. Copy the repo file from the ISO to local repos.d directory.

# cp /media/rhel6/media.repo /etc/yum.repos.d/rhel6.repo

3. Modify the file /etc/yum.repos.d/rhel6.repo

baseurl=file:///media/rhel6/

4. Update the OS

# yum update

5. Unmount the file system

# umount /media/rhel6

6. Remove the temporary repo file

# rm /etc/yum.repos.d/rhel6.repo

7. Reboot the server

8. Check the OS version.

# cat /etc/redhat-release

Managing Activation Key using Hammer commands

1. To create an activation key,

# hammer activation-key create --name "rhel70ak" \
 --content-view "rhel70cv" --lifecycle-environment Library \
 --organization "MyCompany"

2. To update the release version on an activation key,

# hammer activation-key update --release-version "7Server"  \
 --organization "MyCompany" --name "rhel70ak"

3. To display and find out the ID of the subscriptions available,

# hammer subscription list --organization "MyCompany"

4. To list and find out the ID of the activation keys,

# hammer activation-key list --organization "MyCompany"

5. Attach the subscription to the activation key,

# hammer activation-key add-subscription --id 2 --subscription-id 12

6. To list the subscriptions attached to an activation key,

# hammer activation-key subscriptions --id 2 --organization "MyCompany"

Managing Content views using Hammer commands:


1. To list all the available repositories,

# hammer repository list --organization "MyCompany"

---|-------------------------------------------------------------------|---------------------------------|--------------|---------------------------------------------------------------------------------
ID | NAME                                                              | PRODUCT                         | CONTENT TYPE | URL                                                                            
---|-------------------------------------------------------------------|---------------------------------|--------------|---------------------------------------------------------------------------------
1  | Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.1            | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7.1/x86_64/kickstart         
4  | Red Hat Enterprise Linux 7 Server - RH Common RPMs x86_64 7Server | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/rh-common/os  
2  | Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server             | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os            
3  | Red Hat Satellite Tools 6.1 for RHEL 7 Server RPMs x86_64         | Red Hat Enterprise Linux Server | yum          | https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/sat-tools/6....
---|-------------------------------------------------------------------|---------------------------------|--------------|---------------------------------------------------------------------------------

2. To create a content view,.

# hammer content-view create --name "rhel70cv" \
 --description "RHEL 7.0 Content View" --organization "MyCompany"

3. To add the required repositories to the content view,

# hammer content-view update --repository-ids 4,2,3 --name "rhel70cv" --organization "MyCompany"

4. Publish the content view so that its contents are locked,

# hammer content-view publish --name "rhel70cv" --organization "MyCompany"

Basic configuration of Satelite 6.1 using Hammer commands

Introduction:
Hammer is the Satellite 6's command line tool.
You can use hammer to manage entities in Satellite instead of using GUI.

To run hammer you need to provide authentication, you can specify the username and password each time,
# hammer -u admin -p

or simple edit /etc/hammer/cli.modules.d/foreman.yml

:foreman:
    :enable_module: true
    :host: 'https://localhost/'
    :username: 'admin'
    :password: ''

If you ever forget the password, you can always reset as below

# foreman-rake permissions:reset
Reset to user: admin, password: qwJxBptxb7Gfcjj5


Here are some basic hammer commands keeping in mind that you have stored the satellite credentials in foreman.ym

1, To create an organization for your Satellite

# hammer organization create  --name "MyCompany"

2. To create a location for your organization

# hammer location create --name "Chennai"

3. To import the manifest that you've downloaded from Redhat site.

# hammer subscription upload --organization "MyCompany" --file /tmp/manifest-file

4. To display all the repository sets available.

# hammer repository-set  list --organization "MyCompany"

5. To enable a repository

# hammer repository-set enable  --organization "MyCompany" \
 --product "Red Hat Enterprise Linux Server" \
 --name "Red Hat Enterprise Linux 7 Server (RPMs)" --releasever "7.0" --basearch "x86_64"

6. To disable a repository

# hammer repository-set disable  --organization "MyCompany" \
 --product "Red Hat Enterprise Linux Server" \
 --name "Red Hat Enterprise Linux 7 Server (RPMs)" --releasever "7.0" --basearch "x86_64"


7. To synchronize a repository

# hammer repository synchronize --product "Red Hat Enterprise Linux Server" \
 --name "Red Hat Enterprise Linux 7 Server (RPMs)" --organization "MyComapany"

Or use the repo id

# hammer repository synchronize --id 1 --organization "MyCompany"

8. Create the Development and Production life cycle environments

# hammer lifecycle-environment create --name "Development" \
--description "Development" --organization "MyCompany" --prior "Library"

# hammer lifecycle-environment create --name "Production" \
--description "Production" --organization "MyCompany" --prior "Development"

Installation of Satellite 6.1 in Redhat Linux

Following procedure will guide you thru the installation of Satellite 6.1 by downloading packages thru Redhat network. 

1. First of all, You need to register the server in Redhat network and then configure proxy for internet connectivity.

Please refer
http://linuxulagam.blogspot.in/2015/12/how-to-register-red-hat-linux-server-in.html

2. Make sure you create the following file systems (space calculation was based on using just RHEL 6 repositories) on the server that is meant for Satellite.

File systems:
/var/lib/pgsql - 2GB
/var/lib/mongodb - 20 GB
/var/lib/pulp - 400GB

3. Enable the repositories requried to download Satellite packages.

# subscription-manager repos --enable rhel-6-server-rpms --enable rhel-server-rhscl-6-rpms --enable rhel-6-server-satellite-6.1-rpms

3. Install Katello (Satellite)

# yum install katello

# katello-installer --katello-proxy-url=http://10.11.12.13 --katello-proxy-port=8081
Installing             -ebug: Coprefix: /unicast                                 [99%] [.............................................................................Installing             Done                                               [100%] [.................................................................................]
  Success!
  * Katello is running at https://myserver.mycompany.net
      Initial credentials are admin / 6VcVnLn5uvzM
  * Capsule is running at https://myserver.mycompany.net:9090
  * To install additional capsule on separate machine continue by running:"

      capsule-certs-generate --capsule-fqdn "$CAPSULE" --certs-tar "~/$CAPSULE-certs.tar"

  The full log is at /var/log/katello-installer/katello-installer.log

4. You need to register the server as satellite in Redhat network by logging into access.redhat.com
or thru the following command

 # subscription-manager register --type=satellite

5. Download the manifest file

6. Do the rest of the configuration like the creation of Organization, Location, import manifest, enable & sync repositories, ...

How to register a Red hat Linux server in Red hat network ?


You need to make sure your server is able to talk to Red hat network thru internet.
For this, you need to add the proxy IP address (provided by your network team) on the file /etc/rhsm/rhsm.conf.

Add the details like proxy ip, port number, user name and password in the file rhsm.conf.

 # vi /etc/rhsm/rhsm.conf
proxy_hostname = x.x.x.x
proxy_port = 8080
proxy_user =
proxy_password =

You may need to add a user name and password for proxy connectivity.
However if the network admin adds your server IP address to the bypass list, then there may be no need to use user name and password for internet connectivity.

Finally you need to register (subscribe) your server in Red hat network.

2. Register the server in Redhat network.
# subscription-manager register --username --password --auto-attach
The system has been registered with id: 2a2334s3-3254-13e3-8r7e-2435324c5e45
Installed Product Current Status:
Product Name:           Red Hat Enterprise Linux Server
Status:                 Subscribed

Sunday, December 2, 2012

YUM Repository

How to create YUM repository on a RHEL Server :

1. Insert and then mount the cdrom as /media

# mount /dev/cdrom /media

2. Create a directory called /myrepo

# mkdir /myrepo

3. Copy all the RPMs from the cd to the local directory

# cp /media/Packages/*.rpm /myrepo

4. Copy the xml file from the CD to the local directory

# cp /media/Server/repodata/6b21fc619d1eccd6fb49237c666f0ce4c68f-comps-rhel-Server.xml /myrepo

5. Create a YUM repository based on the cdrom. This can be done by creating the below file.

# cat > /etc/yum.repos.d/myrepo

[myrepo]
name=rhel6
baseurl=file:///media
enabled=1
gpgcheck=0

^d

Now you can install any rpm using yum command which will install the software from /media ie., your cdrom

6. Install createrepo rpm ( including its dependents)

# yum install createrepo

7. Create a local repository

# cd /myrepo
# createrepo -g 96b21fc619d1eccd6fb49237c666f0ce4c68f-comps-rhel-Server.xml -x /myrepo

8. Finally you have to change the below file

/etc/yum.repos.d/myrepo :

[myrepo]
name=rhel6
baseurl=file:///media
enabled=1
gpgcheck=0

9. Now you have finished creating a local repository on your server.
You can install any individual rpm or groups by just invoking yum command.

Here are few commands to show different ways to use yum command:

1. To install an individual rpm and also install its dependents

# yum install package-name

2. To install a group of rpms

# yum groupinstall group-name

3. To list all the packages available in the repository

# yum list

4. To list only the packages that are installed
# yum list installed

5. To list all the groups available in the repository

# yum grouplist

6. To display information of a group of packages

# yum groupinfo group-name

7. To display information of a package
# yum info package-name

8. To uninstall a package
# yum remove package-name

9. To uninstall a group of packages
# yum groupremove group-name

10. To update a package
# yum update package-name

11. To update a group of packages
# yum update group-name


12. To search for a package using a keyword
# yum search keyword

13. To know which package a file belongs to
# yum provides /usr/bin/screen

14. To list your current (enabled) yum repositories
# yum repolist

15. To list all yum repositories
# yum repolist all

Few other info,

yum conf file:   /etc/yum.conf
yum repo file: /etc/yum.repos.d/


You still have a lot to learn about YUM. So keep reading.

Wednesday, August 1, 2012

Access Control List

Access Control List (ACL) is a list of permissions attached to a file or directory.

Pre-Requisite:

To set ACL for any file or directory, the underlying filesystem should be ACL enabled which you have to mention while mounting the filesystem.

To make it permanent, you need to edit /etc/fstab and add "acl" under options field for the specific filesystem.

Ex:
LABEL=/data             /data                   ext3    defaults,acl        1 2

After modifying the /etc/fstab file, you have to remount the filesystem.

# mount -o remount /data


Now we can start setting the ACL on any file or directory located under /data filesystem.

To set full permission for a user on /data,
# setfacl -m u:user1:rwx /data

To set only read/execute permission for a user on /data/file1,
# setfacl -m u:user1:r-x /data/file1

To set full permission for dba group on /data/oracle directory,
# setfacl -m g:dba:rwx /data/oracle

To set full permission to user1 and group1 on /data directory,
# setfacl -m u:user1:rwx,g:group1:rwx /data

To revoke the ACL for a user on /data,
# setfacl -x u:user1 /data

To view the current ACL values on /data,
# getfacl /data

To revoke write access for all users and groups on a file,
# setfacl -m m::rx /data/file1

Above command will set the mask value as "r-x".

To copy the acl of one file to another,
# getfacl file1 | setfacl --set-file=- file2

You can also use the below method to copy the acl rights between files.

$ getfacl /data/file1 > acls.txt
$ setfacl -f acls.txt /data/file2

Friday, July 20, 2012

User and Group Management in Redhat Linux

Here are some configuration files which you should be familiar.

/etc/passwd :
Contains the database of information of all the users.
The format of the file is

username:password:uid:gid:gecos:directory:shell

/etc/shadow :
The actual password of every user is stored in /etc/shadow, indicated by an x in the password field.
As /etc/passwd is readable by all users, storing even encrypted passwords in it makes password guessing easier.
However, /etc/shadow is more secure because it is readable only by programs that run with root privileges, such as login and passwd.

Here is a sample line from /etc/shadow
johny:$1$EmRh1cmZ$gkXY30H43D7NtpQXjm9F01:11589:0:99999:7:::

It contains the following fields,
- The account name
- The account’s encrypted password
- The number of days since 1 January 1970 that the password was last changed
- The number of days permitted before the password can be changed
- The number of days after which the password must be changed
- The number of days before the password expires that the user is warned
- The number of days after the password expires before the account is disabled
- The number of days since 1 January 1970 after which the account is disabled
- Reserved for future use


/etc/group :
Contains the database of information of all the groups.
The format of the file is
groupname:password:gid:userlist

where
groupname is the name of the group
- password is an optional field containing the encrypted group password
- gid is the numeric group ID number
- userlist is a comma-separated list of the user account names that comprise the group

For ex,
finance:x:507:jacob,maylyn,nancy


Now lets see some commands,

Q. To create a user account with default settings,

# useradd jacob

In this case,
the home directory will be /home/jacob,
shell will be bash
uid will be the next unused UID

Q. To show the default values taken while creating a user account,

# useradd -D

Q. To set a password for the newly created user account,

# passwd jacob

Q. To change the gecos(description) of a user account,

# usermod -c "Jacob Oyden" jacob

Q. To delete a user account

# userdel jacob

Q. To delete a user account along with its home directory,

# userdel -r jacob

Q. To create a group for finance department,

# groupadd finance

Q. To create a group in a specific guid,

# groupadd -g 1000 finance

Q. To delete a group,

# groupdel finance

Q. To lock a user account,

# passwd -l jacob

Q. To unlock a user account,

# passwd -u jacob

Q. To change the user name of an existing user account,

# usermod -l joyden jacob

above command change the username from jacob to joyden.

Q. To change the 'uid' of a user account,

# usermod -u 1023 jacob

Above command will also update all files and directories rooted in the user’s home directory automatically to the new UID, but any files outside of the user’s home directory must be altered manually.

Q. To show the user account expiry information,

# chage -l jacob

Q. To change user account expiry information,

# chage jacob

Q. To list all the shells (or you can refer the file /etc/shells for the available shells),

# chsh -l

Q. To change the shell of a user,

# chsh jacob

Monday, February 21, 2011

Managing HBAs and SAN disks in Redhat Linux 4 & 5

Redhat 5 :

To list the LUNs and their paths :
# multipath -ll

To display pv information on a multipath :
# pvdisplay /dev/mapper/mpath0

To find the server hardware details :
# dmidecode <- hardware info To scan for new LUNs: # ls /sys/class/fc_host host0 host1 # fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l

# echo "1" > /sys/class/fc_host/host0/issue_lip

# echo "- - -" > /sys/class/scsi_host/host0/scan

# echo "1" > /sys/class/fc_host/host1/issue_lip

# echo "- - -" > /sys/class/scsi_host/host1/scan

# cat /proc/scsi/scsi | egrep -i 'Host:' | wc -l

# fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l



RHEL 4.6 :

To see HBA details like firmware, wwn,etc.. :
# cat /proc/scsi/qla2xxx/0

To list the HBAs along with their HBA :
# adapter_info

To scan for new LUNs:
# hp_rescan -a

To show the WWN of a LUN :
# scsi_info /dev/sdb


To list the configured Qlogic adapters:
# lspci | grep -i qlo


To list the LUNs:
# /opt/hp/hp_fibreutils/lssd

Output will be like

sda H,B,T,L

where
H is the host number of the HBA
B is the bus number (normally 0)
T is the target number
L is the LUN number
is a string which uniquely identifies the storage array.

To remove a lun from OS:
# echo "1" > /sys/block/sd/device/delete
# echo "scsi remove-single-device H B T L" > /proc/scsi/scsi
# echo "1" > /sys/class/scsi_host/host/device/targetH:B:T:L/H:B:T:L/delete

Wednesday, December 1, 2010

Swap Space

1. To setup swap space on a newly created partition :
# mkswap /dev/sdb3

2. To enable the swap partition :
# swapon /dev/sdb3

3. To enable the above swap device at boot time, add the below line to /etc/fstab

/dev/sdb3 swap swap defaults 0 0

4 To create a swap file:

a. Create an empty file
# dd if=/dev/zero of=/swapfile bs=1024 count=65536

b. Create swap space on the file
# mkswap /swap-file

c. Enable the swap file
# swapon /swap-file

d. Add the below line to /etc/fstab
/swap-file swap swap defaults 0 0

5. To remove a swap file

a. Disable swap on the file
# rmswap /swap-file
b. Remove the corresponding entry in /etc/fstab
c. Delete the file
# rm /swap-file

Kernel Module

1. To list the currently loaded kernel modules :
# lsmod

2. To load a module :
# modprobe hid
For detailed output:
# modprobe -v hid

3. To unload a module (only the unused and undependent modules) :
# rmmod hid

4. Module files are kept under /lib/modules//kernel/drivers/

5. To display information about a specific module :
# modinfo -d hid

Identifying a system using /proc Filesystem

1. To show the OS (Kernel) version:
# cat /proc/version

2. To identify the processor details :
# cat /proc/cpuinfo

3. To identify the memory information :
# cat /etc/meminfo

4. To show the raid devices :
# cat /proc/mdstat

5. File containing the disk partition details :
/proc/partitions

6. File containing the swap details :
/proc/swaps

7. File containing the uptime details :
/proc/uptime