Solved: How to reset root password in Redhat Linux or CentOS

In this post we will discuss how to reset the root password of a Redhat linux server if you forgot it.

  • Reboot the server
  • While you are at boot menu press “Up or Down” arrow key to prevent system from booting.
  • Select the boot device and press “e” to edit it.(refer Image 1)

Image 1

  • Scroll down the program with arrow key, till you see a line starting with “linux16”. That line will have words “rhgb quiet” .(refer Image 2)
Image 2
  • Now change  “rhgb quiet” to init=/bin/bash  as in image 3.
Image 3
  • After making the change press “ctrl x” to boot the system.
  • Screen will now take you to command prompt without asking for password.

On the command prompt remount root as read-write.

mount -o remount,rw /

Now execute “passwd” command to change the password of root user.  (refer image 4)

Tip:

  1. Pick strong password else it will throw error of bad password and may not change the password.
  2. If you are getting error “passwd command not found” ensure that your machine is booted with the disk and not the ISO. Many people working on VMs make this mistake so you are not alone 🙂
  • If you are using SElinux you will have to run this extra relabel step before reboot or else you won’t be able to login with the new password.
touch  /.autorelabel
  • Finally reboot the server
exec /sbin/init

Now you should be able to login with new password.

Hope this post is helpful to you. Do let me know if you have any query.

Solved: How to mount ISO in a linux VM

In this post we will discuss how to mount ISO in Linux VM running inside Virtualbox or VMware.

Virtualbox

You can mount ISO in Linux VM running on Virtualbox by following these steps

  • Select the running machine window.
  • Click on Devices > Optical Devices
  • Choose disk image, browse and select ISO .(Refer image below)

  • Now go to the redhat linux server and execute the mount command
 mount /dev/cdrom /mnt

VMware

  • If the linux VM is in VMware. You can select the iso image in vmware console similar to what we did for virtual box.
  • Right click on the machine > “Removable Devices” > “CD/DVD” > Settings. Browse and select the ISO. Check mark on “Connected”.
  • Finally execute the following command in Linux VM.
    mount /dev/sr0 /mnt
  • If you do “df -h” new ISO should be mounted and visible to you as /mnt .

Tip: If you are getting error /mnt busy ensure that /mnt is not already mounted. If /mnt is already mounted either unmount /mnt first and try again or create a new directory and mount the ISO on the new directory.

Solved: How to use nmcli for adding new IP and managing network in Redhat Linux

In our last post we have seen how to use nmtui for network management. In this post we will see how to use nmcli for doing the same activity.

“nmcli” is a command line interface. Benefit with both nmtui and nmcli is that you don’t have to update the network configuration files manually. All the required changes are done by nmtui and nmcli themselves.

Good thing with nmcli is that you don’t have to install any extra package like nmtui. nmcli is generally included with NetworkManager.

  • Let’s create our new connection.
[root@cloudvedas ~]# nmcli con add type ethernet con-name cldvds-2 ifname enp0s3 ip4 192.168.99.103/24 gw4 192.168.99.1
Connection 'cldvds-2' (33de1c00-4ab4-4777-0a43-c004f0bd47ff) successfully added.
[root@cloudvedas ~]#

In the above example we are using these parameters:-

Connection name:- cldvds-2

Network Interface:- enp0s3

IP/Netmask:- 192.168.99.103/24

Gateway:- 192.168.99.1

  • Check in nmcli if our new connection is present.
[root@cloudvedas ~]# nmcli con show
NAME                 UUID                                 TYPE       DEVICE
System enp0s8    00cb8200-feb0-44b7-a378-3fdc720e0bc7 802-3-ethernet enp0s8
enp0s3           1a03478c-0307-4f23-a7fa-247ad74c37bf 802-3-ethernet --
cldvds-1         303ccf07-e77c-4770-b787-370407f73edc 802-3-ethernet enp0s3
cldvds-2         33de1c00-4ab4-4777-0a43-c004f0bd47ff 802-3-ethernet --
[root@cloudvedas ~]#

We can see the new connection cldvds-2 is created.

  • Activate the new connection
nmcli con up cldvds-2
  • If you are following up from the last post we will first deactivate our old connection cldvds-1 and then activate our new connection cldvds-2 .
[root@cloudvedas network-scripts]# nmcli con down cldvds-1 ; nmcli con up cldvds-2
  • Let’s check if our ip got plumbed

Yes we can see the new IP up and running

  • As I said earlier “nmcli” will automatically update the config file. You can find the file in the directory “/etc/sysconfig/network-scripts” . Cross check the contents of the file
cd /etc/sysconfig/network-scripts
cat ifcfg-cldvds-2

You can also modify the connection properties. Let’s say you want to add DNS server to the connection we created.

[root@cloudvedas ~]# nmcli con mod cldvds-2 ipv4.dns "192.168.99.254"

If you want to assign IP using DHCP you can create a new dhcp connection

[root@cloudvedas ~]# nmcli con add type ethernet con-name dhcp-1 ifname enp0s3

You can activate the new dhcp connection.(Be careful because if you are connected with the same interface which you are changing, you will lose the connection.)

nmcli con down cldvds-2 ; nmcli con up dhcp-1

Bonus:-

If you want to add an IPv6 IP to the interface you can do it with ip6 and gw6 options.

[root@cloudvedas ~]# nmcli con add type ethernet con-name cldvds-ip6 ifname enp0s3 ip4 192.168.99.104/24 gw4 192.168.99.1 ip6 fe80::cafe gw6 2001:db8::1
Connection 'cldvds-ip6' (83fb7f17-fc2f-424c-b446-33c929abcb56) successfully added.

Activate the connection

[root@cloudvedas ~]# nmcli con down cldvds-2 ; nmcli con up cldvds-ip6

If you no longer need a connection you can delete it after deactivating it.

[root@cloudvedas ~]# nmcli con down cldvds-ip6
[root@cloudvedas ~]# nmcli con delete cldvds-ip6

Hope this post is helpful to you. Do let me know if you have any query.

Solved: How to change hostname using nmtui or nmcli in redhat linux

In our last post we have seen how to change hostname manually or with hostnamectl .

In this post we will discuss how to change hostname with nmtui and nmcli tools.

nmtui

Let’s first try with nmtui tool

  • If you don’t have the nmtui tool installed, you can install it using yum
yum install NetworkManager-tui
  • Invoke the nmtui interface from the command line by executing as root user
nmtui
  • In the menu select “Set system hostname” as shown below

  • Write the new hostname which you want to keep.  We want to change it to “prodvedas”.

  • To make it effective restart the “hostnamed” service
systemctl restart systemd-hostnamed
  • Now if you login with new session or do “su -” in same session you should see new hostname.

nmcli

Let’s try changing the hostname with nmcli tool in Redhat Linux.

  • To check the current hostname
nmcli general hostname
  • If you want to change the hostname
nmcli general hostname prodvedas
  • To make it effective restart hostnamed service
systemctl restart systemd-hostnamed
  • Now if you login with new session or do “su -” in same session you should see new hostname.

Hostname changed by any of the above method will be persistent across reboot.

If you are trying to change hostname of AWS EC2 linux instance the process will be slightly different. Refer this post to change AWS EC2 instance hostname.

Refer this post to change IP using nmtui and nmcli.

Solved: How to use nmtui and nmcli tool to configure network in Redhat Linux

In this post we will see how to use nmtui for network management. This can be a very useful tool for starters in Redhat Linux 7.

  • Login to your server using putty and execute command “nmtui” to invoke the interface. If your machine is not in network you can login via console and follow the same steps mentioned below.
  • If you don’t have the nmtui tool installed, you can install it using yum (Note: If you don’t want to install a new package in your server you can use nmcli for network configuration. Refer the post for how to configure network with nmcli )
[root@cloudvedas ~]# yum install NetworkManager-tui
[root@cloudvedas ~]# nmtui
  • Once you get the interface you can navigate using Arrow keys , Tab key and make selection using “enter” key. So, using arrow key select “Edit a connection” and press enter.

  • We have two network interfaces enp0s8 and enp0s3 . Today we will be configuring enp0s3. As enps0s8 is already configured and in use. So once highlighted enp0s3 go to “Add” and press enter.

  • Select the type of connection. For this tutorial we are selecting “Ethernet”.

  • Once in “Edit connection” section enter “Profile name” , “Device”.  If you want static IP select “Manual” for IPv4 and select “Show”.

  • Once you select  “Show” enter your IP detail with subnet id. Here subnet id is /24 or 255.255.255.0 . Also enter gateway. If you want to use DNS enter DNS server details else leave it blank and select OK.

  • Once the IP configuration is done select “OK” again. Now you can see the new connection that you have created. Select “Quit” to come out.

  • Now let’s activate the connection. Execute “nmtui” in putty or console again and select “Activate a connection”  and press Enter.

  • Navigate with arrow key select the interface and then move right and Press enter on “Activate”. This will activate your interface as in image below.


  • Check if the new IP is configured.

  • Also let’s check in “nmcli” about the new connection.

If you want to change hostname refer this post on how to change hostname with nmtui or nmcli .

Hope this post is helpful. Do let me know if you have any query.