Automate safe system upodates with a single script (for APT + systemd systems)

THE PROBLEM Keeping a Linux system fully updated usually means doing several things by hand: Update APT package lists Upgrade installed packages Remove unused dependencies and cached files Update Flatpak apps (if you use Flatpak) Update firmware via fwupd (if available) Decide whether to reboot or shut down None of that is hard, but it is repetitive and easy to skip steps, especially firmware updates. This script turns that whole workflow into a single, safe command. REQUIREMENTS This script assumes: Package manager Uses APT Example: Debian, Ubuntu, Linux Mint and similar Init system Uses systemd (for systemctl reboot/poweroff) Shell bash (script uses “#!/usr/bin/env bash” and “set -euo pipefail”) You can run it with: bash script.sh Privileges Your user has sudo rights Optional components Flatpak (optional) If not installed, Flatpak steps are skipped fwupd (fwupdmgr, optional) If not installed, firmware steps a...

Users and Groups

ORDER OF THE STARTUP FILES


© 2022 edX Inc.


Most often, ~/.basrh contains the aliases, customised commands or a modification of the behaviour of the already existing ones.

$ alias
To list the current aliases

Key files for Users and Groups:
  • /etc/group
  • /etc/passwd
  • /etc/group


USERS

id
Displays info of the user. The logged one if with no argument. 

$ useradd -m -c VISUALISED-NAME -s /bin/bash USERNAME
-m creates the home directory
-s select the shell to use. To see the available shells, view the file /etc/shells

When using useradd, the default settings are written in /etc/default/useradd
The initiation config files to create a new home directory are located in /etc/skel

$ userdel -r USERNAME
-r to remove the home directory

SUDO privileges
Config file: /etc/sudoers
Config directory, empty by default: /etc/sudoers.d


GROUPS

$ group USERNAME
To list the groups the username belong to

$ groupadd GROUPNAME

$ groupdel GROUPNAME

$ usermode -a -G USERNAME GROUPNAME
To add a user to a group
-a to be sure to append the user to the group list instead replacing the group list with the new addition
-G to have the list group the user belong to after the new addition


FILE OWNERSHIP

$ chown ug+w, o-r NOMEFILE
Adds Write permission to the User and the Group, and removes Read permission to Other

Alternatively:

  • 4 if read permission is desired
  • 2 if write permission is desired
  • 1 if execute permission is desired
In this way:
$ chmod 165 NOMEFILE
sets only execute for the user (1), read and write for group (4+2=6), and read and execute for others (4+1=5).

$ chown NEWUSER:NEWGROUP FILENAME
changes the user and the group the file currently belong to.

chown NEWUSER FILENAME
changes the user the file currently belong to.

chown :NEWGROUP FILENAME
changes the group the file currently belong to.

$ chgrp NEWGROUP FILENAME
changes the the group the file currently belong to.

Comments