Thursday, January 21, 2016

how to change mysql root password in rhel6 ?

I recently had to reset the MySQL root password due to the fact that initializing it the way I assumed it should did not work. The following procedure will work in CentOS/RHEL/Scientific Linux and Fedora.

After installing MySQL using

# yum install mysql-server
I can run the command

# mysqladmin -u root password 'new-password'
Trying to log in with the following failed

# mysql -u root -p
with the following error

Access denied for user 'root'@'localhost'
Decided to not spend more time as it’s a fresh MySQL installation. And did the following to reset the root password for MySQL.

Resetting the root password

1) Stopped the MySQL service.

# service mysqld stop
2) Started MySQL in safe mode.

# mysqld_safe --skip-grant-tables &
3) Logged in using root.

# mysql -u root
4) Reset the password.

> use mysql;
> update user set password=PASSWORD("mynewpassword") where User='root';
> flush privileges;
> quit
5) Stop MySQL in safe mode.

# service mysqld stop
6) Start MySQL.

# service mysqld start
7) Log in using the new password.


# mysql -u root -p

Friday, January 15, 2016

What is the command for finding the highest memory occupied file in Linux ?



# du –ah / | sort –n –r | head –n 1

Option Explanations :du  – estimate file space usage
a – write counts for all files, not just directories
h – print sizes in human readable format (eg. 1K 234M 2G)
sort – sort lines of text files
n – compare according to string numerical value
r – reverse the result of comparisons
head – output the first part of files

n – number of lines

How to change hostname in Red Hat 6 ?


There are several ways to change the hostname of a machine running Redhat 6.  These also works on CentOS, Fedora and older/other Redhat variants.

First: The "hostname" command.

You can use the hostname command to see the current host name of the system.

# hostname
linux4freshers.com


You can also use the hostname command to change the host name of the machine.

# hostname linuxforfreshers.com

Then issue the hostname command again to see the changes.
# hostname
linuxforfreshers.com

This only makes a temporary or non-persistent change of hostname.

Second: The /etc/sysconfig/network configuration file. (preferred method)

In order for the change to survive a reboot, or to make it persistent, you must change it in the /etc/sysconfig/network-scripts/ifconfig-eth0 file.

Open the file in your favorite editor and change the following line to reflect your desired hostname.

HOSTNAME=linuxforfreshers.com

After making changing to the configuration file you need to restart the network service in order to read that file.

/etc/init.d/network restart
NOTE: Do not do this remotely (via ssh) or you will lose your connection.

If you issue the hostname command now, you will see the hostname has changed.

Third: The /proc/sys/kernel/hostname entry.

Another simple way to change the hostname is to echo the hostname into the /proc/sys/kernel/hostname file.

echo "linuxforfreshers.com" > /proc/sys/kernel/hostname


NOTE: Using the /etc/sysconfig/network file is the preferred method to set the permanent hostname of a system.  Anything in the /proc/sys/kernel/hostname file will be overridden by the /etc/sysconfig/network file during a reboot.

Saturday, December 19, 2015

How to change default login shell permanently in linux ?

  
In Red hat Linux the default shell you login to is /bin/bash but in case you want to change the default login shell follow the below procedure

To check the currently logged in shell

# echo $SHELL
/bin/bash

To view all the available shells in your machine

# chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

You can also view the available shell details from the below file
# less /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

To change the shell temporarily
To do this just provide the full path of the shell you want to use. But this is just a temporary change as next time you switch terminal you will login to the default shell
[root@linuxforfreshers ~]# /bin/sh
sh-4.1#
As you see above my shell prompt changed from /bin/bash to /bin/sh

To change the shell prompt permanently
# chsh -s /bin/sh
Changing shell for root.
Shell changed.
[root@linuxforfreshers ~]#
But as you notice even though our shell was changed successfully but still we see bash shell prompt.

NOTE: To make the changes affect you need to log out and log back in
Using username "root".
root@192.168.8.130's password:
Last login: Fri Mar 21 10:15:03 2014 from 192.168.8.20
-sh-4.1# echo $SHELL
/bin/sh
-sh-4.1#

So now as I try to login I see my default login shell is changed to /bin/sh

Which file is responsible for assigning shell by default?
What if you want next time you create a user, he/she should get different shell and every time you don't change their shell manually

Check the below file
# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes


As you see the SHELL argument has /bin/bash as default. Just change this value to any shell you want to provide for a new user.

Saturday, December 12, 2015

how to assign network setting in rhel 7 using nmtui and nmcli ?

How to assign network in RHEL 7?


networking two ways

lagacy
network manager

networkmanager
--------------

rpm -qa | grep -i Networkmanager

systemctl status NetworkManager

There are  three  different ways assign network settings

GUI ----->Graphical
text ... nmtui   --->Text based
cli .... nmcli    ----> Command line



Using lagacy network service
----------------------

planing to add manually values for eth0

vim /etc/sysconfig/netwok-scripts/ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp

for static

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none   or static
IPADDR=172.25.X.11
PREFIX=24  or  NETMASK=255.255.255.0
GATEWAY=172.25.X.254
DNS1=172.25.254.254

:wq
sytemctl restart NetworkManager

To assign  system name (hostname)
Using command line

hostnamectl set-hostname serverx.example.com

or

vim /etc/hostname
serverx.example.com

before rhel7 .....to set hostname

vim /etc/sysconfig/network
HOSTNAME=serverx.example.com


updating name server info

vim /etc/resolv.conf
nameserver 8.8.8.8

or local dns 172.25.254.254


local name mapping
------------------
if u have to systems .... call with nicknames ...alias name user /etc/hosts
give ip call that system with name  ( nss switch will manage this proccess)
ex:-  172.25.x.11 system1
     172.25.x.10 system2

vim /etc/hosts

172.25.x.11 system1
172.25.x.10 system2
:wq






using nmtui

nmtui stands for Network Manager Text User Interface.
nmtui is actually a very easy text based tool to configure IP address and host names. Just type “nmtui” on command prompt and follow the simple steps

Now choose your connection type after selecting “Edit a connection”. I am choosing ethernet as I don’t have any other connection to my virtual machine.








As I showing here in rhel7 configuring IP addresses. So I had selected “edit” to manually set the ip address





Now after selecting “manual” you can configure ip addresses as per your specifications.

After you press “OK” to come out of this window. Don’t forget to activate the network connection again.



Once you are done with the nmtui tool in rhel7 configuring IP addresses.  You can check using ‘ifconfig or ip a or hostname –i.



Using  nmcli (Network Manager Command Line Interface )

show the connections using

nmcli connection show
nmcli connection show eno1

Configure an IP address
nmcli connection modify eno1 ipv4.addresses 192.168.0.5/24

Configure an IP address with default gateway
nmcli connection modify eno1 ipv4.addresses 192.168.0.5/24 \  ipv4.gateway 192.168.0.1 ipv4.never-default no

Configure an additional IP address
nmcli connection modify eno1 +ipv4.addresses 192.168.0.6

Add a static route
These will be saved in the route-<interface> file in /etc/sysconfig/network-scripts/ :


nmcli connection modify eno1 +ipv4.routes '192.168.111.0/24 192.168.99.1'