How can I use the
chown command to change the ownership of all a folder's subfolders and files?
Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE... or: chown [OPTION]... --reference=RFILE FILE... Change the owner and/or group of each FILE to OWNER and/or GROUP. [...] -R, --recursive operate on files and directories recursively [...]
So you need to run (probably with
chown -R USERNAME:GROUPNAME /PATH/TO/FILE
Or, if the group shall be the specified user's primary group (usually same name), you can also omit the
GROUPNAME and just give the
USERNAME: with a colon (no space before it!). It will be set implicitly:
chown -R USERNAME: /PATH/TO/FILE
To only change the user and leave the group as it is, just specify
USERNAME and no group name and no colon:
chown -R USERNAME /PATH/TO/FILE
To only change the group and leave the owner user as it is, just specify
:GROUPNAME with a leading colon:
chown -R :GROUPNAME /PATH/TO/FILE
Either get to the terminal display mode as described elsewhere or do a ssh login from another computer. Usually the account is intact and it will be accessible via ssh.
You may also have an account on the same machine without the login loop problem. If you do, then login to that account (assuming it will let you sudo).
Once in, open a terminal and find the directory under which you can see the username directories. i.e.
if any of the user directories is owned by root change it by running:
sudo chown -R username:username /home/username
This example is based on an architecture where the user directories are under
ls -l again to confirm the directory is owned by the user.
This was tested on Ubuntu 20.04