Centos 7 root login

General support questions
Post Reply
elevantista
Posts: 3
Joined: 2021/03/30 11:49:34

Centos 7 root login

Post by elevantista » 2021/03/30 11:57:02

Hi! I am in a complicated situation and need an advise.
I cannot login as root in our Centos 7 web server.
I have tried resetting the password, and it said "the password is successfully changed."
However, when I try to login as root, it keeps saying that the password is incorrect.
There is another user account, and I can login using that account.
Only root account is prohibited from login.
Any suggestion how to solve this problem?
Thank you so much for the help.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Centos 7 root login

Post by TrevorH » 2021/03/30 14:14:37

If you reset the password using single user mode or some method like that then you've probably corrupted the selinux context on /etc/passwd and/or /etc/shadow. Boot with enforcing=0 on the kernel command line to come up in permissive mode and run restorecon -RFv /etc/passwd /etc/shadow to fix it then reboot normally.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

elevantista
Posts: 3
Joined: 2021/03/30 11:49:34

Re: Centos 7 root login

Post by elevantista » 2021/03/31 01:34:52

Thank you for your information.
We will try as you suggested. Due to the limited knowledge on Linux boot system,
can you guide us How to make "Boot with enforcing=0 on the kernel command" in detail?
Thanks in advance.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Centos 7 root login

Post by TrevorH » 2021/03/31 05:49:50

Boot up, at the grub menu which lets you select the kernel version, hit 'e' to edit it, highlight the kernel line and edit that, scroll to the end of the line that starts with either linux16 or linuxefi and append a space followed by enforcing=0 to it and then hit ctrl-x to boot using that change.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

User avatar
avij
Retired Moderator
Posts: 3046
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: Centos 7 root login

Post by avij » 2021/03/31 08:53:30

An alternative reason for why you might not be able to log in as root is if you have PermitRootLogin in /etc/ssh/sshd_config set to something else than "yes". There may also be other security mechanisms that affect this.

It is generally a good idea to prevent logging in as root. The key question here is: are you able to su to the root account from the other account, eg. su - root ? If yes, then the root user's password is correct. Again, if you can "su" to root, I would advise not touching the settings at all.

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: Centos 7 root login

Post by MartinR » 2021/03/31 10:19:47

If you are in the wheel group you might be able to get in with

Code: Select all

$ sudo -i
which will create a root shell for you after requiring your password. Of course you need to have been configured to allow this before you had problems getting into root!

Post Reply