Showing posts with label Centos. Show all posts
Showing posts with label Centos. Show all posts

Monday, May 8, 2017

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

Hello Friends,

In this post, I would explain to you how to resolve one of the most intreseting issue on linux servers "Kernel Panic". I think the linux lovers much awaited such issue while they are working on Unix troubleshooting part.

As everyone knows Kernel are most importent part of any operating system and if it is crashed that's means your system crashed.

Normally kernel panic occur when you upgrade the server or upgrade the packages on the server. Here, you can find one of the Kernel panic issue as describe below.

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
Pid: 1, comm: swapper Not tainted 2.6.32-502.el6.x86_64 #1
Call Trace:
 [<ffffffff815292bc>] ? panic+0xa7/0x16f
 [<ffffffff81c2b432>] ? mount_block_root+0x216/0x2cb
 [<ffffffff81002930>] ? bstat+0x2b0/0x980
 [<ffffffff81c2b53d>] ? mount_root+0x56/0x5a
 [<ffffffff81c2b6b1>] ? prepare_namespace+0x170/0x1a9
 [<ffffffff81c2a92a>] ? kernel_init+0x2e1/0x2f7
 [<ffffffff8100c20a>] ? child_rip+0xa/0x20
 [<ffffffff81c2a649>] ? kernel_init+0x0/0x2f7
 [<ffffffff8100c200>] ? child_rip+0x0/0x20


Solution : Normally this issue occur while you upgrade your server using yum and after reboot server is not boot due to kernel panic problem. This problem occur while kernel version has not been changed properly.

You can boot your linux server in grup mode and check the kernel and initrd paramtere. Match both the parameter if they are using same kernel version. During upgrade the initrd version normally not changed so you can manually change the correct kernel version entry in this file.

Once you modified the initrd files boot the server and make a same changes in grub.conf file too, otherwise once you take a reboot or shutdown the machine same kerenl panic error will occur.

[root@localhost]# vi /etc/grub.conf

#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-504.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vstorage-root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vstorage/root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-504.el6.x86_64.img

In above example, the default value 0 identifies the first title option to be used as default, the corresponding kernel version in title option line as 2.6.32-504.el6.x86_64 and the initramfs image file as initramfs-2.6.32-504.el6.x86_64.img. 

Before changing thing please take a backup of grub.conf file. now you can rename the kernel version in the initrd line and matched the same version at both the line and reboot the server, after reboot your linux machine will boot normally.

Hope your kernel panic issue will be resolved after reading this post. Please let me know if you are still facing this issue, I would try to help you.

How To Fix “Device eth0 does not seem to be present, delaying initialization” Error

This Ethernet card error is normally occur on Linux operating system like CentOS, Red Hat Linux etc. When you try to up the Ethernet card it is showing you the above topic error.

So in this post, we will provide you the step by step solutions and troubleshoot all the issue related this error.

In the initial step, you will check which Ethernet card is down , for this you can run the "ifconfig -a" command. Using this command you can check how many internet card is present on the server and on which Ethernet card used IP address.

Let's suppose you are using eth0 on your machine, and if this Ethernet card not taking any ip address and now show on your device that means it is down right now, so please try to start Eth0 device as given below command.

[root@localhost]# ifup eth0
Device eth0 does not seem to be present, delaying initialization

If your internet card show such issue that means you have an issue with MAC address. So in this post I would explain you how to resolve such issue.

1. In this step, please check the MAC Addresses are set correctly or not. For checking this you need to go the network card directory "/etc/sysconfig/network-scripts"

[root@localhost]# cd /etc/sysconfig/network-scripts

[root@localhost]# cat ifcfg-eth0

HWADDR=”00:15:5D:00:91:91”

In the configuration file, you can see the current hardware address of eth0 card, I have show you only HWADDR entry of my eth0 file. In this directory you can see if other Ethernet card is present or not. In my Linux machine i have two Ethernet card , please find the below second Ethernet card MAC address.

[root@localhost]# cat ifcfg-eth1

HWADDR=”00:15:5D:00:91:90”

2. Now we will see which link is present on the system currently and which is not active, for this you can use the below command to check the status.

[root@localhost]# ip -o link

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN \    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000\    link/ether 00:15:5D:00:91:90 brd ff:ff:ff:ff:ff:ff

3: eth2: mtu 1500 qdisc   pfifo_fast state UP qlen 1000\ link/ether 00:15:5D:00:91:91 brd ff:ff:ff:ff:ff:ff

Here, no eth1 but there is an eth2 present on the system, so might be problem is that the eth0 is renamed to eth2 but we will confirm with below command.

[root@localhost]# dmesg | grep eth0

udev: renamed network interface eth0 to eth2
udev: renamed network interface rename3 to eth0

From this command it shows that udev rename the network interface, so in the next step we will remove the wrong entry and configure the Ethernet card 

3. Now please open the network rules file to confirm the mac address. Please open this file "/etc/udev/rules.d/70-persistent-net.rules" 

[root@localhost]# cat /etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:5d:00:91:90", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:5d:00:91:91", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:5d:00:91:91", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Looks like there are multiple entries for the same MAC address. Removed the incorrect entry and restart the interface using below command.

[root@localhost]# ifup eth0

Now you eth0 card is up and if you are running "ifconfig -a" command you can see the eth0 card with mac address. 

Hope you are get the solution of the above issue, also please let me know if you have any other issue.

Tuesday, April 4, 2017

How to Configure Proxy Settings in Linux

In this post, I will explain , how we set or configure the proxy setting in Linux server. Usually when you work on the cooperate server you work behind the proxy. So if you are trying to download any packages or software on the Linux operating system machine, you need to configure the proxy on your browser or on system profile.

1. If you want to set http_proxy shell variable on Linux terminal or bash shell, then please use the below command or method to set the proxy settings on terminal.

# export http_proxy=http://Proxy_IP:Proxyport

or

# export http_proxy=http://Proxy_Domain:ProxyPort

You can use above command to set the proxy on bash shell or on terminal. You can use Proxy IP as well as Proxy DNS name to configure the proxy on shell. In my case I have use proxy IP on my server.

#export http_proxy=http://192.168.1.70:8080

If you want to use https proxy then please run the below command to set the proxy settings on bash or any other shell.

#export https_proxy=https://Proxy_IP:ProxyPort

or

#export https_proxy=https://Proxy_Domain:ProxyPort

You can use this proxy on open shell only if you close the terminal or shell then you need to set proxy variable again.

If your proxy use authentication then you need to give proxy user name and password while you are running the above command.

#export http_proxy=http://Proxy_User:Proxy_Password@Proxy_IP:Port

2. If you want to setup proxy variable for all users then you need to set proxy environment as a global variable. To do this you need to set proxy variable on /etc/profile file.

# vi /etc/profile

export http_proxy=http://Proxy_IP:Proxyport

or

export http_proxy=http://Proxy_User:Proxy_Password@Proxy_IP:Port

3. If you want to set the proxy access to a specific user then you need to set the variable on their bash profile.

# vi /home/vibhor/.bash_profile

Append the following line:

export http_proxy=http://Proxy_User:Proxy_Password@Proxy_IP:Port

or 

export http_proxy=http://Proxy_IP:Proxyport

You can use the https proxy or ftp proxy also only required to change the name of the varibale. 

Monday, March 20, 2017

10 Practical Examples of RPM Commands in Linux

In this post, I will explain you the usage of RPM (Red Hat Package Manager) command with an example. RPM commands are widely used in Linux operating system to install, remove or update the packages on operating system.

RPM (Red Hat Package Manager) is a default open source and package management utlity which is widely used on Redhat, CentOS linux operating system. You can install , remove, upgrade the packages using this commnad. In this post We will explain each syntax with an example so you can understand how this command is very useful on linux operating system. So here, we will explain best 20 example which is related to Red Hat Package Manager.

1. How to Check an RPM Signature Package:

This command with syntax is used for to check the PGP signature of packages before installing them on your Linux systems and make sure its integrity and origin is fine.

[root@locahost]# rpm --checksig vsftpd-2.2.2-14.el6.x86_64.rpm
vsftpd-2.2.2-14.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

2. How to Install an RPM Package:

Using below syntax you can install the rpm packages on the linux system.

[root@localhost]# rpm -ivh vsftpd-2.2.2-14.el6.x86_64.rpm
Preparing...               ########################################### [100%]
1:vsftpd                    ########################################### [100%]

On the above syantx we are using "-i" option to install the rpm packages on Linux operating system.

3. How to check dependencies of RPM Package before Installing:

If you want to check which packages or dependency is required for RPM packages then you can run the below command to check the dependency.

[root@localhost]# rpm -qpR samba-winbind-3.6.23-12.el6.x86_64.rpm

Here, you can find the syantx meaning of the above command.
-q : Query a package.
-p : List capabilities this package provides.
-R: List capabilities on which this package depends.

4. How to Install a RPM Package Without Dependencies:

If you want to install the packages without any dependency please use the below syntax.

[root@localhost]# rpm -ivh --nodeps samba-winbind-3.6.23-12.el6.x86_64.rpm
Preparing...                       ########################################### [100%]
1:Samba-winbind             ########################################### [100%]

The above command forcefully install rpm package by ignoring dependencies errors, but if those dependency files are missing, then the program will not work at all, until you install them.

5. How to check an Installed RPM Package:

If you want to check which RPM package is installed on the operating system then please use -q option with package name.

[root@localhost]# rpm -q samba
package samba is not installed

If you see the samba packages is not installed on my system so it is show you this message.

[root@localhost]# rpm -q vsftpd
vsftpd-2.2.2-14.el6.x86_64

You can see the above ftp server packages is installed on the system.

6. How to Upgrade a RPM Package:

If you want to upgrade any RPM packages then please use "-U" syntax with rpm name.

[root@localhost]# rpm -Uvh vsftpd-3.0.2-11.el6.x86_64.rpm
Preparing...             ########################################### [100%]
1:vsftpd                 ########################################### [100%]

If you see the above example the packages is upgrade with the new version of vsftpd.

7. How to Remove a RPM Package:

If you want to uninstall or remove the package from the server then please use "-e" erase option is used to remove package.

[root@localhost]# rpm -evv vsftpd

Using above command we can remove the packages with all dependency.

8. How to Remove an RPM Package Without Dependencies:

If you want to remove installed packages without any dependecy then use the below syntax to remove the rpm.

[root@localhost]# rpm -ev --nodeps vsftpd

Using above syntax "--nodeps" we can remove the packages without dependency.

9. How to Import an RPM GPG key:

If you want to import the RPM GPG key then please verify RHEL/CentOS/Fedora packages, you must import the GPG key.

[root@localhost]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

So using above syantx we can import the GPG key on the server.

10. How to List all Imported RPM GPG keys:

To print all the imported GPG keys in your system, use the following command.

[root@localhost]# rpm -qa gpg-pubkey*
gpg-pubkey-0608b895-4bd22942
gpg-pubkey-7fac5991-4615767f

You can see the above entry these are the GPG key which is installed on the server.

Tuesday, March 14, 2017

How to disable the SELinux in Linux machine

In this post, I will explain you the how to disable SELINUX on Redhat or CentOS Operating system. Before going to main work first we need to understand what is SELINUX and how its work on Linux enviorement.

Security-enhanced Linux (SELINUX): SELinux is know as Security enhanced linux system which is the security feature of the Linux kernel system. It is define the security Policy which makes system proctative agaginst the misconfiguration of the daemons. SELinux running in 3 modes which is disabled, enabled and permissive. We will explain these mode in configuration steps.

How to disable SELinux on Linux system:

1. In the first step you can check the current status of SELinux. To do this please run the below command.

[redhat]# getenforce
Enabled

"getenforce" command is used for checking the current status of SELinux.

2. As you see on my machine when I run the above command my SElinux is enabled, So in this step we will change the SELinux mode.

[redhat]# vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Normally selinux configuration file you can found on the above location. You can edit the SELINUX entry to disabled. All the command is run by super user "root" only.

3. Once you change the entry in SELinux configuration file then for permanent effect you need to take a reboot of the system.

[redhat]#init 6

Once you reboot the server all the configuration files changes has been done.

4. In the last step you will run the "getenforce" command again to verify the new status of SELinux.
[redhat]# getenforce
Disabled

If you comparison the both step 1 and this step output you can found that SELinux policy is not disabled on the Linux operating system.

Friday, February 17, 2017

SQL command for MySQL database on Linux operating system

In this post, i will explain you how we will create, import, export & backup of MySQL database.

Please find the below points which is very useful to database admin on Linux operating system.

How to create new database:

CREATE DATABASE <DATABASENAME>;

e.g. CREATE DATABASE VIBHOR;

In this example I have created the "vibhor" named database, you can replace database name according to your choice.

How to create mater user with all level access to all available databases:

GRANT ALL ON *.* TO <USERNAME> IDENTIFIED BY '<PASSWORD>';
e.g. GRANT ALL ON *.* TO TESTDBUSER IDENTIFIED BY 'TESTDBUSER';

In this example I used "testdbuser" MySQL user on the server. 

How to take backup (dump) of a database:

For this command you need not to login into the database. Once you login on the database please run the below command to take a dump of server.

mysqldump --lock-all-tables -u <USERNAME> -p -h <DATABASESERVERNAME/IP ADDRESS> <DATABASENAME> > <NEWDUMPFILENAME>.sql

e.g. mysqldump --lock-all-tables -u ABC -p -h MACHINE1 VIBHOR > VIBHOR_16022017.sql

After this command you have to provide DB password only and dump will be done in the folder in which u are working currently.

How to take backup (dump) of a table's:

For this command you need not to login into the database.

mysqldump -u <USERNAME> -p <DATABASENAME> <TABLENAME> > <NEWDUMPFILENAME>.sql

e.g. mysqldump -u testdbuser -p testdb test_book > test.sql

After this command you have to provide DB password only and dump will be done in the folder in which u are working currently. for dumping multiple table use space between the table names.

How to run a database dump to another machine:

Go to the folder in which sql dump file is placed and then connect with your Database in which you want to run dump and then run below command.

source <FILENAME>.sql;

e.g source VIBHOR_16022017.sql;

How to take dump only triggers and procedure from database:

mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt -u <USERNAME> -p <DATABASENAME> > <NEWDUMPFILENAME>.sql

e.g. mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt -u TESTDBSUER -p VIBHOR > VIBHOR_16022017.sql

After this command you have to provide DB password only and dump will be done in the folder in which u are working currently.

How to show procedure/function code:

SHOW CREATE PROCEDURE <STORED PROCEDURE/FUNCTION NAME>\G

e.g. SHOW CREATE PROCEDURE FLIGHT_INVOICETOSAP\G;

How to increase filed width of a table attribute:

ALTER TABLE <TABLENAME> CHANGE <EXISTING_FIELD_NAME> <NEW_FIELD_NAME> <DATATYPE>(<NEW_FIELD_WIDTH>);

e.g. ALTER TABLE TRILOK CHANGE PASSENGER_NO PASSENGER_NUMBER VARCHAR(30);

field name and data type change is not recommended.

How to display all existing databases:

SHOW DATABASES;

Using this command you can show all the created database list on the Linux server.

How to display all existing tables:

SHOW TABLES; 
SHOW TABLES LIKE '<CHARACTERS>%';

Using this command you can check all the tables which is created on the database. 

How to recover a MySQL root password:

This is one of the best way to recover the MySQL root password if you forget. I always used below method to reset the root password.
  • Stop the MySQL server process.

# /etc/init.d/mysql stop
  • Start again with no grant tables.

# mysqld_safe --skip-grant-tables &
  • Login to MySQL as root. Set new password.

# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
  • Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# /etc/init.d/mysql start
  • Set a root password if there is on root password.

# mysqladmin -u root password newpassword
  • Update a root password.

# mysqladmin -u root -p oldpassword newpassword

How to grant privileges to a user:

If we need to provide the privileges to user we will use below two method. I will describe the step by step method for this one.

METHOD 1

Allow the user "bob" to connect to the server from localhost using the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by 'passwd';
mysql> flush privileges;

Give user privileges for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql>INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;

METHOD 2

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;

To update info already in a table.

Load a CSV file into a table:

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);

Dump all databases for backup:

Backup file is SQL commands to recreate all databases.

# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -p password --databases databasename >/tmp/databasename.sql
Dump a table from a database.

# [mysql dir]/bin/mysqldump -c -u username -p password databasename tablename > /tmp/databasename.tablename.sql
Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -p password databasename < /tmp/databasename.sql
Create Table Example 1.

Using above method we can take database back very fast. I hope through this post you can easily able to create MySQL database, MySQL dump, table creation etc work.

Friday, February 10, 2017

How to Create Local YUM Repository on CentOS 7 / RHEL 7

In this post, I describes how to setup a local Yum repository on CentOS 7 & RHEL 7 server operating system.

The local YUM repository is the most significant way to perform any type of package installation without any internet connection. If you have to install software, security updates and fixes often in multiple systems in your local network, then having a local repository is an efficient way. 

All required packages are downloaded over the fast LAN connection from your local server, so that it will save your Internet bandwidth and reduces your annual cost of Internet.

Now, please find the step by step method to create a YUM repository on RHEL 7 & CentOS 7.

Mount the Local Media:

In this step we mount our CentOS 7 / RHEL 7 installation DVD. For example, let us mount the installation media on /mnt directory.

#mount -o loop /dev/cdrom /mnt

In my Linux machine i will insert the ISO on cdrom and mount it on /mnt directory.

Copy or Extract the Media:

In this step, we will extract or copy iso files to local machine. For this work we will create a one mount point directory and copy all the packages files from /mnt.

#mkdir /centos
#cp -rvf /mnt/* /centos

So all the packages are copied on the "/centos" directory.

Install repository packages:

In this step, we will create repository but before this we need to install the "createrepo" rpm on the YUM server.

For createrepo, you need to install some dependency rpm which are listed in "Packages" folder.

#rpm -ivh libxml2-python-2.9.1-5.el7_0.1.x86_64.rpm
#rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm
#rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm
#rpm -ivh createrepo-0.9.9-23.el7.noarch.rpm

Once these required packages is installed we create the repo using createrepo command.

#createrepo -v /centos/Packages

Remove the Online Repository:

Please remove the old repository from /etc/yum.repos.d directory. In this directory all the default local centOS / RHEL repository are exist.

#rm -rf /etc/yum.repos.d/*

Create Local Repository:

In this step we will create the local repostiory which is always kept as a local. Using this local repo we can install all the packages and their dependency.

#vi /etc/yum.repos.d/local.repo

[Packages]
baseurl=file:///centos/Packages
gpgcheck=0
enable=1

After save the file your local.repo repository has been created. In next step we will enable it.

Enable Local Repository:

After successfully creation of YUM repository we will enable it.

#yum clean all
#yum repolist all

Using this repolist command you can check the newly created and existing repository on the server. After that you can easily install the pacakges using YUM in RHEL 7 & CentOS 7.

Friday, February 3, 2017

How to Shrink or reduce size of LVM partitons in RHEL/CentOS

LVM (Logical Volume Manager) is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes.With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes.

LVM allows users to create partitions from more than one disk and allows them to extend the filesystem size online within few seconds.

In this post, we will see how we can shrink the size of an LVM partition without losing data.

On my linux virtual machine, the VG name is “rootvg” and LV name is “Vibhor” which has 60 GB size. I want to reduce the LV size to 4GB. Please note down the following points before proceeding with the shrinking of filesystem.

  • Make sure the current disk usage of the filesystem is less than the size to which you are going to reduce the logical volume.
  • Always take a backup of filesystem data before doing any size change in LVM as a simple mistake in command can cause filesystem corruption and hence loss of data.

Now, please find the below steps which we need to follow for reduce or shrink the partition size.

Umount the filesystem:

We will check the file system through fsck command but before running fsck on the filesystem, it should be unmounted.You can unmount the filesystem “/vibhor” as follows.

#umount /Vibhor

Performing filesystem check:
Before proceeding with reducing filesystem, “fsck” should be done in order to avoid inconsistency of filesystem data.
#e2fsck –f /dev/mapper/rootvg/rootvg_vibhor

Resizing filesystem:

Now, we will reducing the size of the Logical Volume, but before we need to reduce the filesystem in it. The command “resize2fs” can be used for this as follows.

#resize2fs –p /dev/mapper/rootvg/rootvg_vibhor 4G

This will decrease or shrink the filesystem size to 4GB.

Reducing the LV size:

After reduce or shrink the filesystem, we can reducing the LV as given below.

#lvreduce –L 4G /dev/mapper/rootvg/rootvg_vibhor

This will reduce the logical volume size to 4 GB. Now I will mount the filesystem again and check it using the command “df –h”. the file system has reduced to 4 GB without losing any data.

#mount /Vibhor
#df –h

This output will show you the reduce filesystem size.

Thursday, February 2, 2017

How to stop USB Mass Storage device in RHEL/CentOS

Hello Friends,

I’d like to disable all USB devices connected to our Red Hat Linux based workstations. I’d like to disable USB flash or hard drives, which users can use with physical access to a system to quickly copy sensitive data from it.

How do I disable USB device support under RHEL/CentOS workstation operating systems. The USB storage drive automatically detects USB flash or hard drives. You can easily force and disable USB storage devices under any Linux distribution.

The modprobe program used for automatic kernel module loading and can be configured to not load the USB storage driver upon demand. This will prevent the modprobe program from loading the usb-storage module, but will not prevent root (or another program) from using the insmod program to load the module manually.


In linux it’s even more easily done, by unloading the usb_storage module:

for disable the usb storage run the below command :-

# modprobe -r usb_storage

for enable the usb storage run the below command :-

# modprobe -i usb_storage

##############################################################################

The easiest way to disable usb storage device in linux is create following file And add following line inside the file

# touch /etc/modprobe.d/no-usb


install usb-storage /bin/true

##############################################################################

How we will block USB on linux machine.

Hello Friends,

We can block the usb drive on linux system very easily. There are several ways using this we can block or open the USB drive on machine.

Here, we will block USB using script. This script is used in any version on Linux ( Redhat, Centos).
You can create a any .sh file on your linux machine and paste this below script content.

##############################################################################

#!/bin/bash
clear ;
yum -y install sshpass &> /tmp/temp ;
apt-get install sshpass -y &> /tmp/tmp ;
echo  " Welcome $USER , *** WARNING: THIS PROGRAM WILL RESTART THE REMOTE MACHINE *** "
echo ""
echo  " 1. Block USB ports of Machine "
echo  " 2. Open USB ports of Machine "
echo ""
echo -ne " Please Select your choice : "
read choice ;
echo -ne " Please Enter the IP address of Machine : "
read ip ;
echo -ne " please Enter the password for $ip : "
read -s pass ;
case "$choice" in

1)      echo -e "\n";
        echo -ne " You are going to Block the USB ports of $ip ,Are you sure you want to continue connecting (Yes/no)? "
    read choice1 ;
        if [ "$choice1" == "no" ];
        then
                exit ;
        else
                sshpass -p $pass ssh $ip  "echo 'blacklist usb_storage' >>  /etc/modprobe.d/blacklist.conf ; echo 'modprobe -r usb_storage' >> /etc/rc.local ; "
        fi

        echo -e "\n"
        echo -ne " $ip needs a reboot, So we are going to reboot $ip machine. Press 0 to EXIT or Press Enter to reboot the Machine."

        read choice2 ;
        if [ "$choice2" == "0" ]
        then
                exit ;
        else
                 sshpass -p $pass ssh $ip reboot ;
        fi

    ;;
2)      echo -e "\n" ;
        echo -ne " You are going to Open the USB ports of $ip ,Are you sure you want to continue connecting (Yes/no)? "
        read choice3 ;
        if [ "$choice3" == "no" ]
        then
                exit ;
        else
                 sshpass -p $pass ssh $ip "sed -i 's/"blacklist usb_storage"/""/g' /etc/modprobe.d/blacklist.conf ; sed -i 's/"modprobe -r usb_storage"/""/g' /etc/rc.local ;"
        fi
    ;;
*) echo "you have not selected the right option, Try Again. Bye"
   ;;
esac

##############################################################################

When you run the script, it is asking for 2 options, first option is used for blocking the USB drive and second option is for open the block usb drive.

Please read the script carefully and please let me know if you have any doubt in your mind. I will try to resolve your query as earliest.

Tuesday, January 24, 2017

How to add a fake dummy null printer in centos 7

Please find the below step by step simple method to add tge fake , dummy or Null printer on Centos7

1. Install the rpm packages for configuration of printer
#yum install system-config-printer*

2. Install cups printer packages
#yum install cups*

3. start the cups services on the centos 7

# systemctl status cups
cups.service - CUPS Printing Service
   Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

# systemctl restart cups

# systemctl status cups
cups.service - CUPS Printing Service
   Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-01-23 09:23:11 GMT; 4s ago
 Main PID: 6121 (cupsd)
   CGroup: /system.slice/cups.service
           └─6121 /usr/sbin/cupsd -f

Jan 23 09:23:11 linux systemd[1]: Started CUPS Printing Service.
Jan 23 09:23:11 linux systemd[1]: Starting CUPS Printing Service...

Please add below line in cupsd.conf if doesn't exist.

# vi /etc/cups/cupsd.conf
FileDevice yes

Command to add a printer-

# lpadmin -p myprinter -E -v file:///dev/null

To check the default printer status-

# lpstat -s
no system default destination
device for myprinter: ///dev/null