# chmod & chown — Linux

Source: https://www.geekswithgeeks.com/en/linux/linux-chmod-chown

> Change permissions and ownership.

## chmod — symbolic mode

Add or remove permissions with `+`/`-` on `u` (user), `g` (group), `o` (other), `a` (all).

```bash
chmod u+x deploy.sh    # owner can execute
chmod go-w notes.txt    # group & other lose write
```

## chmod — numeric mode

r=4, w=2, x=1 — sum them per triplet. `755` = rwxr-xr-x, `644` = rw-r--r--.

```bash
chmod 755 deploy.sh     # owner: rwx, group/other: r-x
chmod 644 notes.txt     # owner: rw-, group/other: r--
```

## chown — change ownership

`chown` changes a file's owner and/or group; usually needs `sudo`.

```bash
sudo chown alice deploy.sh
sudo chown alice:devs deploy.sh
```

**Quiz:** What does `chmod 644 file` set?

- [ ] rwxrwxrwx
- [x] rw-r--r--
- [ ] r--r--r--

*Answer:* rw-r--r--. 6=rw-, 4=r--, 4=r-- for owner, group, other respectively.
