Wednesday, July 22, 2015

How to reset root user's password in RHEL7

Problem working with VM's is that you might not use one for a long time and when you had to use it again, you probably won't remember the root user's password! Yeah, ran into that situation myself again today and here are the steps to reset root user's password in RHEL 7. This is a bit different to how we used to do in RHEL 6.x.

1. On the grub menu, press 'e' to enter edit mode.
2. Once in edit mode, look for the line starting with 'linux16', and replace 'rhgb quiet' with 'init=/bin/sh'
3. Press ctrl+x to start booting with the modified grub entries
4. The file system will be mounted in read-only mode. Remount it in rw mode using the below command -  
mount -o remount, rw /
5. Use passwd command to reset the password for root user
6. Execute below command to ensure the selinux contents of modified files are restored properly after reboot -
touch /.autorelabel
7. Execute exec /sbin/init to continue normal boot process or exec /sbin/reboot to reboot the system

Thanks to original poster.

Network unavailability in RHEL7 (VMware) & how did I fixed it.

I was playing around with RHEL 7 evaluation version by firing up a VM lately. One of the issues that I faced was there was no network available other than lo. I ran out of my tricks after almost an hour and finally found the solution in here. Below is what I did to fix the issue -

1. Edited 'Red Hat 7 Eval.vmx'
2. Changed the value of guestOS from "other26xlinux" to "rhel6-64"
3. Added below entry -
ethernet0.virtualDev = "e1000"

Fired up the VM after those changes and voila, it picked the network now. All good!

Saturday, June 27, 2015

Simple shell script to change the extension of multiple files

Below is a simple script that I came up with today since I had to change the extension for a bunch of files. Thanks to original author for the script, I just added interactive touch to it.

for f in *.$1; do
mv -- "$f" "${f%.$1}.$2"
done

The script can be run as below -

./script old_extn new_extn

Thursday, July 17, 2014

Road to RHCE - Day 8

Day 8

Network Configuration

IP classes

Class          Range           Default subnet mask        Prefix

Class A  -> 1 to 126     -> 255.0.0.0                      -> 8
Class B  -> 128 to 191 -> 255.255.0.0                  -> 16
Class C  -> 192 to 223 -> 255.255.255.0              -> 24
Class D  -> 224 to 235
Class E  -> 236 to 254

255 -> broadcast address

127 -> loopback address


Subnetting -> dividing a large network into small networks
Subnet Mask -> unique id for such small networks


To configure network using TUI client

system-config-network

[! there are 2 options available - device & dns configuration]

Device configuration


Name                             : eth0
Device                            : eth0
Use DHCP                      : None
Static IP                         : 192.168.0.109
Netmask                        : 255.255.255.0
Default gateway IP         : 192.168.0.254
Primary DNS server        : 192.168.0.254
Secondary DNS server    : 192.168.0.254

[! this is a sample setup that uses static IP]


To update the changes

service network restart


To check the IP of the system

ifconfig
ip addr show


Associated config files

1. /etc/sysconfig/network-scripts/ifcfg-eth0
[! to configure the ip]

2. /etc/sysconfig/network
[! contains the hostname of the system]

3. /etc/resolv.conf
[! contains the DNS info]



To get the current hostname of the system

hostname


To know the status of all configured devices

service network status



-- End of Day 8 --

-- End of SA1 --

Wednesday, July 16, 2014

Road to RHCE - Day 7

Day 7



Backup and Compression


To check the directory size

du -sh /etc/


To create an archive

tar -cvf [archive_name] [list_of_files]


To know the type of a file

file [filename]


To extract the contents of a tar file to a different path

tar -xvf [archive_name] -C [destination_path]


To compress an archive (or file)

zip [zip_filename] [source_filename]


To decompress a compressed file

unzip [zip_filename]


Using gzip (only for archives)

gzip [archive_filename]

[! gunzip [filename] to decompress]


Using bzip2 (more compression than gzip)

bzip2 [archive_filename]

[! bunzip2 [filename] to decompress]


To compress while archiving

tar -cvfz [archive.tar.gz] [list_of_files]

[! z -> gzip; j -> bzip2]


Process Management

To monitor the processes via gui

gnome-system-monitor


To list the processes running in current session

ps

[! ps -a for all active processes across sessions; ps a for all processes (including inactive ones) across sessions]


To list the parent proces id and the owner info

ps -f


To list the processes in a tree format

ps af


To list all processes including system ones

ps x


To know the session detail

w


To know users login info

lastlog


To run a process in background

[process/service_name] &


To list the background processes started by users

jobs


kill

To list all the available options with kill command

kill -l


Below are few of the important options

9   -> kill
15 -> terminate
18 -> continue
19 -> stop (temporarily)


To stop a job/process temporarily

kill -19 %[job_id | proces_id]



To resume the stopped job/process

kill -18 %[job_id | process_id]


To make a background process run in the foreground

fg %[job_id]

[! Ctrl+z -> to stop temporarily; bg %[job_id] to take that to background]


To terminate a process

kill %[job_id]
kill [process_id]

[! kill command defaults to option 15, if nothing else is specified]


To force kill a process

kill -9 [process_id]


To kill using the process name

pkill -9 [process_name]


top

To list the running processes

top

[! the display gets refreshed every 3 sec; top -d 1 to refresh the display every 1 sec]


To kill the process based on id

k


To sort top output based on memory utilised

Shift+M


To sort based on CPU usage

Shift+C


To sort based on user

U



-- End of Day 7 --