How to Change a Forgotten Root Password in a CentOS / RHEL 7 Environment

MarGib June 19, 2026
🌐 🇵🇱 Polski · 🇬🇧 EN


Human memory is good, but sometimes short. It may also happen that there is a need to log in to a system that was installed by someone else and that person is no longer available. The reasons may be different and are not important here. What is important is the method that allows logging in to the CentOS 7/RedHat 7 system when the password is not known.

Błędne hasło root w CentOS 7

The method of changing the root password in CentOS/RedHat environments has not changed for many years. The general idea of recovery has also remained the same as in older versions. However, it should be remembered that currently in version 7, the init environment has been replaced by systemd, and we also have to deal with SELinux.

The password change is performed in 5 steps:
  1. The GRUB2 bootloader entries must be edited to access single user mode.
  2. Mounting the / partition to enable reading and writing (changing from "ro" to "rw")
  3. Changing the root password
  4. Setting SELinux to relabel the file system on boot
  5. Restarting the system

STEP 1 – Editing GRUB2 and entering single mode

To access the system when the root password is not known, you need to restart the host and then edit the GRUB2 bootloader by pressing "e".

After this operation, the next screen should look similar to the one below.

Depending on the terminal resolution, you may see more or fewer lines. Using the cursor keys, navigate to the "rhgb quiet" entry

In the "rhgb quiet" entry, type: init=/bin/bash.
After editing, press CTRL+x to boot the system in single mode.


STEP 2 – Mounting the root partition in Read&Write mode

After entering single mode, the root partition must be mounted to enable writing changes. This is done using the mount command.

# mount | grep root

# mount -o remount,rw /

# mount | grep root

As a result, we should get:

STEP 3 – Changing the root password
Now you can easily set a new password for root using the passwd command.

# passwd

The screen will look like this:


STEP 4 – SELinux relabeling
In this step, you need to make sure that the SELinux labels are updated. This is done by creating a hidden file. This will cause SELinux to relabel the file system on the next boot.

# touch /.autorelabel


STEP 5 – Restarting the system
After completing the above steps, all that remains is to restart the system and log in with the new root password.

# exec /sbin/init

After restarting, you can log in to the root account with the new password.
Facebook X E-mail

Comments

Dodaj komentarz

Explore

Labels

Google 15 Linux 12 AI 9 news 9 browsers 8 Opera 7 Windows 7 chrome 7 coaching 7 facebook 7 www 7 Artificial Intelligence 6 Software 6 entertainment 6 web applications 6 God 5 Microsoft 5 Mind 5 Security 5 Web browser 5 books 5 curiosities 5 new technologies 5 Docker 4 RedHat 4 applications 4 artificial intelligence 4 automation 4 containers 4 people 4 photography 4 technology 4 trivia 4 Android 3 BIG DATA 3 Business 3 FAQ 3 FIFA 3 Firefox 3 Google projects 3 Red Hat 3 Vivaldi 3 Windows system administration 3 algorithms 3 bash 3 communication 3 computer science 3 extensions 3 faith 3 games 3 help 3 human 3 interesting websites 3 interface 3 media 3 money 3 network 3 personal competencies 3 reading 3 religion 3 system administration 3 tools 3 virtualization 3 web browser 3 websites 3 Asus 2 CentOS 2 Centos 2 Configuration 2 Docker Machine 2 Drones 2 Intel 2 Intelligence 2 LLM 2 Machine Learning 2 Programs 2 RHEL7 2 Technology 2 ansible 2 better life 2 children 2 cloud storage 2 communities 2 computer intelligence 2 computers 2 conferences 2 creativity 2 data 2 death 2 documentary 2 earning 2 education 2 emotions 2 file storage 2 fix 2 free application 2 free courses 2 free knowledge from the internet 2 free training 2 genius 2 good movie 2 hacker 2 health 2 investments 2 knowledge 2 learning 2 mind manipulation 2 mind programming 2 mobile apps 2 mobile phones 2 movie 2 multimedia 2 opensource 2 personal development 2 personal thoughts 2 photos 2 plugin 2 programming 2 shell 2 terminal 2 torrent 2 trick 2 wealth 2 weather 2 web 2 wisdom 2 youtube 2 64 bit 1 7 1 AI Frameworks 1 AI History 1 AI Safety 1 AI in sports 1 AIMP 1 Acquisition 1 Alan Watts 1 Alexander Gerst 1 Anonymous 1 Anthropic 1 Automation 1 Banking 1 Bill Warner 1 Black Mirror 1 Bonding 1 Bono 1 C++ 1 CUDA 1 Chemtrails 1 Claude 1 Claude AI 1 Coaching 1 Constitutional AI 1 Couching 1 Darwin 1 Debian 1 Deluge 1 DevOps 1 Diagnostics 1 Digitalization 1 Dystrybucje 1 EA GAMES 1 EA SPORTS 1 Email 1 Emigration 1 Enterprise Linux 1 Error 1 FIFA 16 1 Fable 1 Flannel 1 Football 1 Free 1 Free Red Hat 1 Free software 1 Future of Finance 1 GUI 1 Generation Z 1 Google Assistant 1 Google activity 1 Got Talent 1 HTML 1 IBM 1 ISIS 1 ISS 1 Intelligent email 1 Interview 1 Islam 1 Islamic State 1 Jacquard 1 Japan 1 Jboss 1 Kali Linux 1 Khan Academy 1 Kylian Mbappé 1 LibreOffice 1 Londoners 1 Maps 1 Marek Jankowski 1 Material Design 1 Medicine 1 Miłosz Brzeziński 1 My take 1 Mythos 1 NVIDIA 1 Netflix 1 Neural Networks 1 New 1 No comment 1 Notion 1 Open Source 1 Opera Neon 1 Opera Touch 1 P2P 1 Pac-Man 1 Pekao S.A 1 Peperclips 1 Perceptron 1 Personal Development 1 Personal Finance 1 Personal development 1 Philosophy 1 Photoshop 1 Poland 1 Poles 1 PowerShell 1 Privacy 1 Productivity 1 Programming 1 Project TANGO 1 Psychology 1 Quotes 1 RHEL8 1 Raspberry PI 1 Raspbian 1 Red Hat Enterprise Linux Developer Suite 1 RedHat 8 1 Robo-advisors 1 Rust 1 SUSE 1 September 23 2017 1 Snip. 1 Social Media 1 Software Engineering 1 Soli 1 Solo Projects 1 Solopreneurship 1 Something from myself 1 Sound 1 Sport 1 The Shack 1 Time Management 1 Tips 1 Tools 1 Tribler 1 U2 1 USB 1 Ubuntu 1 VentuSky 1 WBC 1 Weave 1 Websites 1 Windows 10 1 Windows errors 1 Work 1 World Cup 1 World Cup 2026 1 World Wide Web 1 X-Files 1 X-files 1 YouTube 1 ZenFone 1 a drop of motivation 1 about this blog 1 achieving goals 1 ad blocking 1 addiction 1 aids 1 animations 1 assertiveness 1 audio 1 automateit 1 autonomous cars 1 awareness 1 bank 1 bash on windows 1 bat files 1 batch 1 battery 1 beliefs 1 beta 1 better living 1 better quality 1 bin/bash 1 blocking 1 blogger 1 body language 1 bookmarks 1 boot 1 bootable usb 1 boxing 1 brain 1 business intelligence 1 c# 1 calc 1 campaign 1 cards 1 chemistry 1 clearance 1 clothing industry 1 cmd 1 code editor 1 coldplay 1 command history 1 command prompt 1 comments 1 configuration management 1 console 1 conspiracy 1 conspiracy theories 1 controversial 1 converter 1 corporate world 1 courses 1 courses for free 1 curl 1 cyberattacks 1 dark mode 1 date and time 1 deep learning 1 developer tools 1 digital clothing 1 disqus 1 document 1 dreams 1 drop of motivation 1 dubai 1 dying 1 e-book 1 economy 1 end of the world 1 end of world 1 energy 1 evolution 1 excel 1 exploitation 1 extreme 1 file sharing 1 file size 1 flash drive 1 flat earth 1 flying 1 food 1 football 1 for sale 1 format change 1 free 1 friend location 1 future of transport 1 future of work 1 game 1 geoengineering 1 graphics 1 graphics editors 1 growing up 1 hacking 1 hard-link 1 hashing 1 helion 1 history 1 hobby 1 hostname 1 hostnamectl 1 how many people live on earth 1 humanity 1 humor 1 immortality 1 innovation 1 installation 1 investing 1 javascript 1 kuba wojewódzki 1 labor market 1 light 1 login 1 machine learning 1 magic 1 make life harder 1 making money 1 material design 1 meditation 1 messenger 1 mindfulness 1 mobile 1 mobile photography 1 motivation 1 mounting 1 mp3 player 1 music 1 music player 1 mysteries 1 net use 1 network resources 1 networking 1 new life 1 new player 1 new things 1 office 1 onestep4red 1 online 1 online courses 1 operating systems 1 outage 1 paper clips 1 parenting 1 parents 1 password 1 password change 1 password recovery 1 pdf 1 penetration testing 1 performance 1 personal data 1 philosophy 1 php 1 plague 1 player 1 podcast 1 poison 1 predictions 1 promissory notes 1 prompt 1 protection 1 psychology 1 questions 1 radar 1 red 1 relax 1 relaxation 1 reportage 1 rest 1 robotaxi 1 root 1 science 1 scientific facts 1 screen 1 screenshot 1 series 1 show 1 skydive 1 sleep 1 small big company 1 smart clothing 1 smartphone 1 social engineering 1 social media 1 society 1 software 1 space 1 sport 1 sports 1 spreadsheet 1 stalking 1 statistics 1 sub-millimeter sensor 1 symbolic link 1 syngrapha 1 system acceleration 1 tablet 1 talk show 1 television 1 terrorism 1 testing 1 the world in numbers 1 threats 1 time travel 1 timelapse 1 tips 1 ubuntu 1 upbringing 1 users 1 viral 1 virtualbox 1 webmaster 1 windows automation 1 word processing 1 work 1 world 1 world cup 2026 1 world wide web 1 you are a miracle 1 zeitgeist 1

Blog archive

Table of contents