Linux users and groups
Linux decides what you may do by who you are (user) and which groups you are in. Many "Permission denied" problems in the labs are really "you are not in the right group".
Linux users (pi, www-data) are separate from MariaDB users (Nypuser). For those, see MariaDB users.
The users you will meet
| User | Who it is |
|---|---|
pi | You |
root | The administrator |
www-data | Apache and PHP run as this user, so web files must be readable by it |
mysql | MariaDB runs as this user and owns /var/lib/mysql |
Groups that matter in this class
| Group | Gives access to |
|---|---|
sudo | Using sudo |
dialout | Serial ports: /dev/ttyACM0, /dev/ttyUSB0 (the Arduino) |
gpio | GPIO pins |
i2c, spi | I2C and SPI buses |
www-data | Shared access to web files (if you set it up) |
See yours:
groups # your groups
groups www-data # another user's groups
Adding a user to a group
sudo usermod -aG dialout pi
:::danger Never forget the -a
-aG means append to the Groups. usermod -G dialout pi without -a removes pi from every other group, including sudo. Then you can no longer use sudo to fix it.
:::
Group changes only apply to new logins. After usermod, log out and back in (or reboot). groups in an old terminal still shows the old list. To try it straight away in the current terminal: newgrp dialout.
Creating and removing users
sudo adduser student # asks for a password and details, creates /home/student
sudo usermod -aG sudo student # let them use sudo
sudo passwd student # change their password
sudo deluser --remove-home student
Use adduser (friendly) rather than useradd (low-level: no home folder or password unless you ask).
Changing your own password
passwd
On a lab Pi, keep the password the class expects, or nobody can help you when you are stuck.
If you removed yourself from sudo
If sudo now says pi is not in the sudoers file:
- Shut down, take out the card, and put it in another Linux computer (or a working Pi with a USB card reader).
- Edit
/etc/groupon the card's second partition and addpiback to thesudoline:sudo:x:27:pi. - Put the card back.
Or re-clone the card if your work is backed up.