Lesson 9: Ownership and sudo — chown and running as root
Last lesson we saw the permissions (rwx). Now we'll meet the other side: ownership. Every file has an owner — in ls -l it's the column with a username. The command chown changes the owner. And for admin tasks (changing ownership, restarting a service, editing a system file) you need admin rights: th
root is the manager with a master key to every door. You work as a regular user so you don't break things by accident, and sudo is borrowing the master key for just one action. chown is changing whose file it is.
- ownership
- Every file has an owner (and a group). In ls -l these are the name columns, e.g. deploy deploy. The owner is usually who can change the file.
- chown
- Changes a file's owner: chown deploy app.log makes deploy the owner. Changing ownership is an admin action, so you usually prefix sudo.
- root (superuser)
- The admin user who can do anything on the system. (Different from the filesystem 'root' / — just the same word.) For safety you don't work as root routinely.
- sudo
- Runs a single command with root permissions. You prefix it to an admin command: sudo systemctl restart nginx. 'superuser do'.