LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-23-2018, 08:35 PM   #1
DevGuy
LQ Newbie
 
Registered: May 2018
Location: London
Distribution: CentOS 7.5
Posts: 25

Rep: Reputation: Disabled
Locked out of Centos 7 remote server


I messed up a password change for root and I am now totally locked out. There are no other user accounts on the server apart from the root account.

I am able to boot from a recovery CD and gain access to the server files. I have modified the following files:

/etc/sysconfig/selinux - to disable SELINUX
/etc/passwd - to change to blank password for root::
/etc/ssh/sshd_config - to change to MaxAuthTries 1000

Now, when I log on to root using blank password, I get:

$ ssh -o PubkeyAuthentication=no root@xxx.xxx.xxx.xxx
root@xxx.xxx.xxx.xxx's password:
Permission denied, please try again.

I think the problem is to do with the file permissions on the files I edited. I think I need to do some kind of chcon on them, but don't know what or how.

Can anyone help me please?
 
Old 05-24-2018, 11:12 AM   #2
kfritz
Member
 
Registered: Aug 2006
Distribution: Slackware, OpenBSD, CentOS, Ubuntu
Posts: 99

Rep: Reputation: 31
Editing files doesn't change the permissions, so unless you copied some other file over the existing files, permissions is not the problem. Since you can mount the filesystem from the recovery disk, you can change the password to whatever you like. Assuming you're mounting your root filesystem read/write on /mnt/sysimage, just do "chroot /mnt/sysimage" and "passwd root".

You can refer to the Red-Hat docs for more info, in particular "Procedure 25.6. Resetting the Root Password Using an Installation Disk":
https://access.redhat.com/documentat..._Root_Password

You should also re-think the wisdom of allowing root login via ssh, or any password-based login, especially if the server is internet accessible.
 
1 members found this post helpful.
Old 05-24-2018, 04:13 PM   #3
DevGuy
LQ Newbie
 
Registered: May 2018
Location: London
Distribution: CentOS 7.5
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thanks for your solution. Because my post was delayed, I had to find the solution elsewhere that's basically same as yours and I managed to correct the problem. It was the first time something like that ever happened to me - copying and pasting of a random 32 character password that went wrong. So, I thought it was more serious than it really was.

For some reason editing the passwd file didn't work for me. So I chroot'ed and used the passwd command instead.

The server is accessible by my IP alone. So having a single user account is more convenient and less to think about.

For anyone else running into this problem, do the following, note selection of an installed shell for chroot:

mkdir /mnt/my_disk
mount /dev/dm-2 /mnt/my_disk
chroot /mnt/my_disk /bin/bash
passwd

Last edited by DevGuy; 05-24-2018 at 04:20 PM.
 
Old 05-24-2018, 04:43 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Also note selinux had been disabled first.
 
Old 05-24-2018, 06:18 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,704

Rep: Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897Reputation: 5897
The /etc/passwd file does not contain any real passwords anymore so directly editing the file does not do anything. The actual encrypted passwords are stored elsewhere.

By default ssh disables using empty passwords so that would of failed even if were successful and from the included link CentOS 7 root needs a password so you probably could not get away without one anyway.
 
Old 05-25-2018, 01:31 AM   #6
DevGuy
LQ Newbie
 
Registered: May 2018
Location: London
Distribution: CentOS 7.5
Posts: 25

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
Also note selinux had been disabled first.
Is that needed? I disabled it only as a random measure because I didn't know what caused the passwd file editing to fail.


Quote:
Originally Posted by michaelk View Post
The /etc/passwd file does not contain any real passwords anymore so directly editing the file does not do anything. The actual encrypted passwords are stored elsewhere.

By default ssh disables using empty passwords so that would of failed even if were successful and from the included link CentOS 7 root needs a password so you probably could not get away without one anyway.
Thanks. This certainly explains it.

Last edited by DevGuy; 05-25-2018 at 01:33 AM.
 
Old 05-25-2018, 01:45 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Quote:
Originally Posted by DevGuy View Post
Is that needed?
Not absolutely required, but it saves having to remember to fix the security context else the new password won't work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Centos 6.3 as remote syslog server eqtime Linux - Server 4 11-13-2012 11:20 PM
Remote CentOS server is slow chekhov_neo Linux - Enterprise 2 04-16-2012 05:25 PM
Remote Desktop from Windows XP to a CentOS server? How To? roshanekka Linux - Server 3 06-15-2010 12:09 PM
How To setup remote access server on centOS 5 bagra Linux - Newbie 2 08-25-2009 06:07 AM
Remote setup of LAMP server on CentOS 5 satimis Linux - Server 19 01-31-2008 11:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 12:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration