Friday, 18 November 2016

HOW TO RECOVER FORGOTTEN ROOT PASSWORD ON REDHAT/CENTOS



Posted by Admin   on Friday, November 18, 2016


In this Artical we are going to learn how to recover forgotten root password.
As a Linux Administrator some time we face challenges when some how we forgot the root password and without root access we can't do any kind of administrative task's in Linux.But luckily there is a easy way to recover the forgotten password.
So let's have look at the step's to recover the root password.
STEP 1 >>

Restart the system and press any key to interrupt the normal boot process to use the menu before it enters in to the Operating System.
After interrupt the normal boot process system will allow us to use the menu to edit the grub so that we can recover the root password.

As we can see the system is allowing us to edit the menu by press "e". So press "e" to go toward next step.

Note :- If you have protected your GRUB by password then it will ask to press "p" to enter the password to unlock the GRUB and then it will allow to edit the menu by pressing "e".
STEP 2 >>

After the main menu now we moved to a new page where we have to edit the kernel argument by pressing "e", As we can see in the snapshot above the Kernel argument is there on second line.

Note : -We can move the cursor by UP and Down arrow on the keyboard.
So select the second line as selected above on the snapshot and press "e" to edit the kernel argument.

As we can see after edit the kernel argument we are able to make changes in the line.

STEP 3 >>

So remove the rhgb quiet type single as shown in the snapshot above and then press ENTER.

After make changes the line would look like this as shown in the snapshot above.
Now as shown on the snapshot above select the kernel line and press "b" to boot Operating System in a Single User Mode.
Now it will take to the shell prompt.
STEP 4 >>
At shell prompt just type below command to reset the password.
$  passwd root    # To reset the root password
Output :

So this is how we can recover the root password.


HOW TO CONFIGURE VNC SERVER IN RHEL/CENTOS/FEDORA



VNC is also known as ( Virtual Network Computing) is a great tool for Graphical Desktop Sharing which allows you to take remote of Linux operating systems using VNC client tool i.e. VNC Viewer, Also you can take remote of Linux Systems from Windows Operating System using same VNC viewer client tool but windows verison (VNC Viewer.exe). It uses Remote Frame Buffer Protocol to remotely control another Computer. VNC is works like Remote Desktop Connections (MSTSC).

Not only in Linux, VNC is available for all known Operating Systems like MAC OS X, Microsoft Windows. The Different variations VNC are Real VNC, Tight VNC, Ultra VNC and so on...

The VNC contains Server and Client end applications, to take control the system desktop remotely, Where in Linux Server-End package includes vnc-server and from client it's VNC Viewer (Available for all OS like Windows, Linux....etc...) OR we can take web based remote from client end by URL "http://VNC-Server-IP-Address:Port-Number".

Ports are used by VNC Server :

a. 5801 - Used to Client Connection over HTTP
b. 5901 - Used to Client connection over RFB (Remote Frame Buffer Protocol)
c. 6001 - Used to X-Application Connectivity.

So let's have a look at Configuration part of VNC Server and VNC Client.

VNC SERVER SIDE CONFIGURATION

STEP 1 : GNOME Desktop Installation >>
   [root@localhost ~]# yum -y groupinstall "X Window System" "Desktop"

STEP 2 : VNC-Server Package Installation >>

Packages Required :

vnc-server.xxx.xxx.rpm

Before Package installation we can check if it's already installed or not by below command.
  
[root@localhost ~]# rpm -qa | grep vnc   # Check if vnc package is installed or not
By-Default the vnc-server package is installed on system but if it's not there then we can install the packages in two ways :

Installation by .rpm Package for Example :
rpm -ivh <Package Name>
 
[root@localhost packages]# rpm -ivh vnc-server-4.1.2-14.el5_3.1.i386.rpm
   Preparing...                ########################################### [100%]
1:vnc-server             ########################################### [100%]
[root@localhost packages]#

Note : You can get the vnc-server-4.1.2-14.el5_3.1.i386.rpm Package from Redhat/CentOS Installation media.
Install by yum Package Manager :
yum -y install <Package Name>
   [root@localhost packages]# yum -y install vnc-server
  
   Loaded plugins: fastestmirror
   Loading mirror speeds from cached hostfile
    * addons: mirrors.vonline.vn
    * base: mirrors.vonline.vn
    * epel: epel.mirror.net.in
    * extras: centos.mirror.net.in
    * updates: centos.mirror.net.in
   Setting up Install Process
   Resolving Dependencies
   --> Running transaction check
   ---> Package vnc-server.i386 0:4.1.2-14.el5_6.6 set to be updated
   --> Finished Dependency Resolution

   Dependencies Resolved

   ================================================================================
    Package            Arch         Version                     Repository    Size
   ================================================================================
   Installing:
    vnc-server         i386         4.1.2-14.el5_6.6            base         2.0 M

   Transaction Summary
   ================================================================================
   Install       1 Package(s)
   Upgrade       0 Package(s)

   Total download size: 2.0 M
   Downloading Packages:
   vnc-server-4.1.2-14.el5_6.6.i386.rpm                     | 2.0 MB     00:17    
   Running rpm_check_debug
   Running Transaction Test
   Finished Transaction Test
   Transaction Test Succeeded
   Running Transaction
     Installing     : vnc-server                                               1/1

   Installed:
     vnc-server.i386 0:4.1.2-14.el5_6.6                                           

   Complete!
   [root@localhost packages]#
STEP 3 : Set the Password for Users for Authentication >>

We need Username and Password for authentication while taking remote from client side, so let's create a password for user root using command vncpasswd.
After run the command it will ask to enter password twice, So enter the same password twice to set the password for VNC remote connection as shown below.
   [root@localhost ~]# vncpasswd
   Password:
   Verify:
   [root@localhost ~]#
Above password will be used while taking remote of  the VNC Server.

Here we set the password for the user root as shown on the output above, but if you want you can create your own username and can be used to take remote of vnc server.

Let's take an Example :

First create a user and set password for that as shown below :
   [root@localhost ~]# useradd elinuxbook
   [root@localhost ~]# passwd elinuxbook
   Changing password for user elinuxbook.
   New UNIX password:

   Retype new UNIX password:

   passwd: all authentication tokens updated successfully.
   [root@localhost ~]#
Now switch to above created user and create password for VNC Remote Authentication using command vncpasswd as shown below :
   [root@localhost ~]# su - elinuxbook
   [elinuxbook@localhost ~]$ vncpasswd elinuxbook
   Password:
   Verify:
   [elinuxbook@localhost ~]$
Note : Keep in mind that above created password for user elinuxbook using command vncpasswd will be used as a VNC remote authentication.

The passwords we have created in above steps using command vncpasswd for user "root" "elinuxbook" are stored in a file "/home/elinuxbook/.vnc/passwd" which is located at home directory of the user.

Note : .vnc is a hidden directory which can be shown by command ls -a as shown below :
   [elinuxbook@localhost .vnc]$ cd
   [elinuxbook@localhost ~]$ ls -a
   .   .bash_history  .bash_profile  elinuxbook  .viminfo
   ..  .bash_logout   .bashrc        .mozilla    .vnc
   [elinuxbook@localhost ~]$ cd .vnc
   [elinuxbook@localhost .vnc]$ ls
   passwd
   [elinuxbook@localhost .vnc]$
As shown on above output the directory .vnc (Highlighted in color Yellow is a hidden directory) and the passwd file is highlighted by Orange color.

STEP 4 : Configure main Configuration File of VNC Server >>

The main configuration file of VNC Server is located at "/etc/sysconfig/vncservers" which is we need to configure to adding users, So follow the below steps.

Edit the 
/etc/sysconfig/vncservers Configuration file do the required changed as shown below.
   # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

   # Use "-nohttpd" to prevent web-based VNC clients connecting.

   # Use "-localhost" to prevent remote VNC clients connecting except when
   # doing so through a secure tunnel.  See the "-via" option in the
   # `man vncviewer' manual page.

   # VNCSERVERS="2:myusername"
   # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

   VNCSERVERS="1:root"
   VNCSERVERARGS[1]="-geometry 800x600"
As shown on output above just edit the /etc/sysconfig/vncservers file and add the hilighted lines by yellow color to your bottom of your configuration file.

Note : replace your username with root and replace the grometry as per your need.

We can mention multiple users as shown below :
   # Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

   # Use "-nohttpd" to prevent web-based VNC clients connecting.

   # Use "-localhost" to prevent remote VNC clients connecting except when
   # doing so through a secure tunnel.  See the "-via" option in the
   # `man vncviewer' manual page.

   # VNCSERVERS="2:myusername"
   # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

   VNCSERVERS="1:root 2:elinuxbook"
   VNCSERVERARGS[1]="-geometry 800x600"
   VNCSERVERARGS[2]="-geometry 800x600"
Now start the VNC Service by below command :
   [root@localhost ~]# /etc/init.d/vncserver start
  
   Starting VNC server: 1:root
   New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

   Creating default startup script /root/.vnc/xstartup
   Starting applications specified in /root/.vnc/xstartup
   Log file is /root/.vnc/localhost.localdomain:1.log

   2:elinuxbook xauth:  /tmp/.gdmUJKWQY not writable, changes will be ignored

   New 'localhost.localdomain:2 (elinuxbook)' desktop is localhost.localdomain:2

   Creating default startup script /home/elinuxbook/.vnc/xstartup
   Starting applications specified in /home/elinuxbook/.vnc/xstartup
   Log file is /home/elinuxbook/.vnc/localhost.localdomain:2.log
 
                                                              [  OK  ]
   [root@localhost ~]#