what is chown root:root doing?

28,645

Solution 1

In general: Do not execute commands from the web if you do not know exactly what they do.

Specially by root !!.

The command chown root:root /home/mynewuser is:

changing the ownership to user:group of /home/mynewuser.

However, the first comment from your linked page adds an -R (keep reading).

Assuming the user kevind (using the specific name you provided) has a main group called kevind also created already (you can create it if needed) the command to revert the effect is:

chown kevind:kevind /home/kevind

Which must be executed as/by root to revert the ownership of root to the user kevind.

A more extensive change to ensure that kevind doesn't have some file owned by root inside his directories (security reasons) is:

chown -R kevind:kevind /home/kevind

That will Recurse inside all directories and subdirectories of the given top directory. That is a safe command, there is no real reason for a user to have a file (or directory) owned by root inside his home directory.

Solution 2

Since the recursive option -R wasn't used, simply using the same command with the mynewuser user and primary group instead of root/root will do it. Assuming like most modern distros whatever you are using puts the new user in its own group with the same name

chown mynewuser.mynewuser /home/mynewuser

as root (or via sudo) will un-do that.

Open a new question with your ssh key issue ...

Solution 3

The command chown root:root changes the user and group of the specified file or directory to user root and group root. I don't know why that answer recommends setting the chowning the directory to root:root.

To partially revert the change, use the command

chown mynewuser /home/mynewuser

This will at least set the user to mynewuser. To find the correct group, you can use either getent or grep the /etc/passwd file for the user, if your system doesn't have getent.

getent passwd mynewuser

grep ^mynewuser: /etc/passwd

You will get a line similar to this:

mynewuser:x:<user>:<group>:...

To include the correct group, use this command, where <group> is the number from the previous line:

chown mynewuser:<group> /home/mynewuser
Share:
28,645

Related videos on Youtube

Kevin Danikowski
Author by

Kevin Danikowski

Particular focus on multi-lingual simplistic react and javascript applications. Additional experiences include: docker, infrastructure, GCP, and business tasks. Otherwise, just building cool sh*t :)

Updated on September 18, 2022

Comments

  • Kevin Danikowski
    Kevin Danikowski almost 2 years

    I read a tutorial and was instructed to do chown root:root /home/mynewuser as part of the process to get my ssh key working with a new user i created "kevind", however it broke the path.

    What does this do?

    How can I reset it back to default? What ever the default would be, /, ~ or something?

    Tutorial came from this answer comment.

  • Kevin Danikowski
    Kevin Danikowski over 5 years
    thank you for your response, I was instructed to use chown -R mynewuser:mynewuser /home/mynewuser/ in the line above, what are the reprocussions of this?
  • ivanivan
    ivanivan over 5 years
    @KevinDanikowski the -R makes it recursive - it will operate on that directory, and any file/directory underneath. Since it is the home directory for that user, that is probably appropriate. However, I wasn't sure of your end goal, and so focused on simply reversing the command that you posted in your question.
  • Deathgrip
    Deathgrip over 2 years
    Your answer does not address the user's question.
  • Peter
    Peter over 2 years
    Shall I delete it @Deathgrip?