Week 6: Users, permissions, file systems and timers
/etc/passwd and passwords (hashes) in /etc/shadow.Why multiple users?
Isolation and security
Accountability (who did what)
Least-privilege principle
Tip
amsa.rootroot (UID 0) can read/write anything and change system config.root.sudo to run one command with elevated privileges.Important
sudo <cmd> runs <cmd> as root.
sudo work?Are this commands familiar? This a situation among many where we need admin rights, and so we run the command with sudo at the beginning.
Caution
If you run tools that create files (e.g., ssh-keygen) with sudo, those files will belong to root and land in root’s home.
A group (identified by GID) is a set of users sharing permissions on files/dirs.
Each user has a primary group and may also belong to other groups.
Useful commands:
groups [user] – list which groups is user part ofid [user] – the same but also shows UID and GIDs/etc/passwd (users)/etc/shadow (passwords)Let’s create and configure a test user
# Create user 'test' with a home dir
sudo useradd -m test
# Create a new group called "testgroup"
sudo groupadd testgroup
# Set a password
sudo passwd test
# Add to 'wheel' group (if desired)
sudo usermod -aG wheel testImportant
When adding a user to a group, for the change to take effect we need to log out and log back in as that user. Another way is to use the su command to change to another user and then back to the affected user. So for example if I add user test to group testgroup, I can do su amsa to switch to user amsa, su test to then switch back to user test which now will be in the testgroup.
Tip
-m creates home dir at /home/
Note
Which groups will a new user have?
Each user can have a home dir, which by default is located at /home/<username>.
Root user’s home dir is not located on /home/root but on /root
Important
It is important to understand when to run commands with root and when not to, do not prepend sudo unless you truly want it for root. As a rule of thumb, avoid using root if you can.
Tip
Running the command cd without specifying which directory do we want to go to will take us to our home dir.
To switch to another user, we do not need to log out and log back in as the other user. Instead, it is possible to switch user temporarily from the terminal.
# Switch to test user (will ask for `test` user password)
su test
# Using sudo (will ask for our user password)
sudo su testNote
Why does the first command ask for test user password and the second one ask for our password?
Tip
Use the whoami command to check which is your current user.
To modify permissions we are going to use chmod command.
Just so you know, instead of changing permissions by using their letters, they can also be referred to using numbers.
| Permission | Value |
|---|---|
| Read | 4 |
| Write | 2 |
| Execute | 1 |
| No perm | 0 |
So for example, this two commands are equivalent:
You may have noticed there that before the three groups of permissions, there is a character that can be a d or a -. This indicates if the file is a directory or not.
For directories, r means you can list files, w means you can create/delete files, and x means you can enter the directory.
setgid is set on a directory, files created inside inherit the group of the directory. setuid has no effect on directories.Note
If both bits are set on a file, the process runs with both user and group of the file.
We’ll create a little c program that prints the user that owns the process when executed.
We’ll run it with sudo, which will make the process be owned by root.
sudo actually doesIf we take a look at the sudo binary, which we can find by running which sudo, we can see that it has the setuid bit set and is owned by root.
So, if sudo is a process that will be owned by root, if it executes another process, that process will also be owned by root.
/etc/sudoers file, where we’ll usually find a line like this:wheel group can run any command as any user on any host.Note
Ubuntu does not use wheel group, but sudo or adm instead. The name wheel comes from early Unix systems, and it was chosen because it was a “big wheel” group with special privileges, “big wheel” being a slang term for an important person.
| Filesystem | Use case | Notes |
|---|---|---|
| ext4 | General Linux systems | Most common Linux filesystem |
| ext2 | Older Linux systems | No journaling |
| xfs | High-performance systems | Good for large files |
| btrfs | Advanced features (snapshots, etc) | Still maturing |
| vfat | USB drives, cross-platform | Compatible with Windows and macOS |
| ntfs | Windows systems | Read/write support in Linux |
| tmpfs | Temporary files in RAM | Very fast, data lost on reboot |
We’ll format a USB drive with ext4 filesystem. First of all We’ll use lsblk to identify the device. Make sure you identify it correctly, as using the wrong device can lead to data loss.
Then, we’ll use mkfs.ext4 to format it, and mount to mount it.
Assuming the partition is /dev/sdb1, we would do:
Warning
Formatting a drive will erase all data on it. Make sure to back up any important data before proceeding.
systemctl and journalctl.Tip
Unlike a long-running daemon, a timer consumes almost no resources while it waits.
Unit=.ExecStart= belongs in the service.Create /etc/systemd/system/amsa-demo.service:
[Unit]
Description=AMSA timer example
[Service]
Type=oneshot
User=amsa
ExecStart=/usr/bin/date --iso-8601=secondsNote
Type=oneshot means the command runs once and exits. Its standard output goes to the systemd journal.
Create /etc/systemd/system/amsa-demo.timer:
[Unit]
Description=Run the AMSA example every minute
[Timer]
OnBootSec=1min
OnUnitActiveSec=1min
[Install]
WantedBy=timers.targetOnBootSec= schedules the first run relative to boot.OnUnitActiveSec= schedules the next run relative to the previous activation.WantedBy=timers.target starts this timer automatically at boot when enabled.Note
These options end in Sec because a number without a unit means seconds. Other time units are accepted too, such as 500ms, 2min, 1h, or 1day.
daemon-reload makes systemd reread unit files.--now also starts it immediately.Important
Enable the timer, not the service. The timer starts the service when required.
# Show the next and previous activation times
systemctl list-timers --all
# Inspect this timer
systemctl status amsa-demo.timer
# Read the output from the service
journalctl -u amsa-demo.serviceTip
To test without waiting: sudo systemctl start amsa-demo.service.
Use OnCalendar= when a task must run at a wall-clock time:
| Value | Meaning |
|---|---|
Mon..Fri 09:00 |
At 09:00 every Monday through Friday |
daily |
Every day at 00:00 (midnight) |
*-*-* 02:30:00 |
At 02:30 every day |
Sat *-*-* 12:00:00 |
At 12:00 every Saturday |
Here, * means “any value” in the year-month-day date fields, while .. specifies a range.
Tip
See the official systemd.time calendar-event documentation for the complete OnCalendar= syntax and more examples. Also, you can check an expression before using with systemd-analyze calendar 'Mon..Fri 09:00'
Note
Persistent=true runs a missed calendar event when the timer becomes active again, for example after the machine was powered off.
# Stop it now, but keep it enabled for the next boot
sudo systemctl stop amsa-demo.timer
# Stop it and disable future automatic starts
sudo systemctl disable --now amsa-demo.timer
# After editing either unit
sudo systemctl daemon-reload
sudo systemctl restart amsa-demo.timerWarning
A system timer runs its service as root by default. Set User= when the task does not need root privileges.
systemctl status amsa-demo.timer
systemctl status amsa-demo.service
journalctl -u amsa-demo.timer -u amsa-demo.service
systemctl list-timers --allCheck these first:
daemon-reload after editing the files?ExecStart= use an absolute executable path?sudo ssh-keygen, where do keys go and why?-rwxr-xr--.drwxr-sr-x?/etc/passwd contain?Persistent=true change?/etc/passwd file: https://www.cyberciti.biz/faq/understanding-etcshadow-file/Ready to have some fun? Check out the second part of the third AMSA activity here!

AMSA 2026-2027 - 🏠 Home