Tag: Password

  • How to reset CentOS 7 root password using console

    How to reset CentOS 7 root password using console

    If you have lost the root password of your CentOS 7 system and have access to the console directly or using KVM, you can reset the password following the instructions below.

    1) Reboot the server, you will see the grub menu.

    CentOS 7 grub menu

    2) Press “e” to edit. You will see the edit screen as shown below.

    centos 7 grub edit

    3) Find the line starting with linux16

    linux16 /boot/vmlinuz-3.10.0-1160.76.1.el7.x86_64 root=UUID=1c419d6c-5064-4a2b-953c-05b2c67edb15 ro no_timer_check console=tty0 console=ttyS0,115200n8 net.ifnames=0 biosdevname=0 elevator=noop crashkernel=auto LANG=en_US.UTF-8
    

    In the fine, find

    ro
    

    Delete everything after that and replace with “rd.break”, so the line looks like the following

    linux16 /boot/vmlinuz-3.10.0-1160.76.1.el7.x86_64 root=UUID=1c419d6c-5064-4a2b-953c-05b2c67edb15 ro rd.break
    

    CentOS 7 enable emergency mode

    4) Boot the system to the emergency mode by pressing CTRL + X, you will get a prompt like the following

    CentOS 7 Emergency Mode Command line

    5) Mount /sysroot in read-write mode. and chroot to the file system

    mount -o remount,rw /sysroot
    chroot /sysroot
    

    6) Reset the root password with passwd command

    passwd
    

    7) SELinux won’t allow modifying system files like /etc/shadow, to allow the change, create a file

    touch /.autorelabel
    

    7) Now reboot the system by typing the “exit” command two times

    exit
    exit
    

    After rebooting, you will be able to log in to the system with the new root password.

    Back to CentOS 7

  • Password Protect Site using htaccess

    To password protect a web site or a sub folder using .htaccess, create a .htaccess file in the folder.

    vi .htaccess
    

    Add following content

    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /etc/apache2/site-logins
    Require valid-user
    

    In this case, i used /etc/apache2/site-logins as AuthUserFile, this will store all user and password. You can change this file path to whatever you need. Make sure it is not accessable from public, so keep it outside of document root of your web site.

    Now create a user with command

    htpasswd -c /etc/apache2/site-logins USER_NAME_HERE
    
  • Password

    https://www.passbolt.com – Open source password manager.
    https://www.grc.com/passwords.htm – Online secure password generator.