Skip to main content

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​

UserWho it is
piYou
rootThe administrator
www-dataApache and PHP run as this user, so web files must be readable by it
mysqlMariaDB runs as this user and owns /var/lib/mysql

Groups that matter in this class​

GroupGives access to
sudoUsing sudo
dialoutSerial ports: /dev/ttyACM0, /dev/ttyUSB0 (the Arduino)
gpioGPIO pins
i2c, spiI2C and SPI buses
www-dataShared 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:

  1. Shut down, take out the card, and put it in another Linux computer (or a working Pi with a USB card reader).
  2. Edit /etc/group on the card's second partition and add pi back to the sudo line: sudo:x:27:pi.
  3. Put the card back.

Or re-clone the card if your work is backed up.