Recover root folder - fix ssh login and file manager

I deleted the initial system user and created a new one from scratch. I believe that when I deleted my initial user I deleted the root folder as well.
When I try to logon via SSH I get the below message.
Could not chdir to home directory /root: No such file or directory

Tools → File Manager is also broken now

Error creating configuration directory: No such file or directory

Is there a way to recover the root folder to fix the above described errors?

OS type and version: CentOS Linux 7.9.2009
Webmin version: 1.973
Virtualmin version: 6.16

You should not delete the root user. Ever. That’s just not a thing that makes sense to do. You can make it impossible to login as root, without doing something crazy (just set the password field to x in /etc/shadow and make sure there are no public keys in /root/.ssh/authorized_keys. Problem solved, it is now impossible to login to the root account via any mechanism other than sudo.

Where did you get the idea to delete your system root user?

Hi Joe,

thank you for that,

Where did you get the idea to delete your system root user?

I certainly did not want or tried to delete root at all. I believe the folder /root got deleted when I deleted another system user I had created few minutes earlier.
This was all done via webmin web interface. - the idea (in my head) is that it’s safer to use UI -.

I clicked on the button to delete the user I created earlier (not root) and I was asked if I wanted to delete all the folders that relate to that user. I clicked yes and that’s when I think the folder ./root got deleted.

The user root exist in webmin and it’s also listed in System->Users and Groups
I can logon via virtualmin and website is live.

The two problems I can see are related to File Manager in webmin and when I login via SSH using root it shows the message that /root folder doesn’t exist.

no public keys in /root/.ssh/authorized_keys
Well there is nothing in /root at the moment. I cannot see the folder at all. That’s what I am trying to recover before anything else.

If it’s only the folder that got removed, you can try recreating it with the following commands:

mkdir /root
chown root:root /root
chmod 0700 /root

You can then go ahead and reboot the server as well as restart webmin after running the above commands.

In Virtualmin, run Recheck configuration and if everything passes, try accessing Tools > File Manager again.

1 Like

thanks for that shillongserver.

Creating the /root folder fixed the problem with the file manager immediately.

in addition I run cp -v /etc/skel/.bash* ~/ and that copied .bash_logout, .bash_profile, .bashrc, in the root directory. The terminal now shows my username rather than -bash-4.2#

That would mean the user had /root as their home directory, which is also not recommended. Every user should have their own home directory, even if they are intended for administrative purposes (via sudo, not by making them have UID 0).

Thanks Joe, That’s correct. my mistake.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.