[Updating this post as I go. Last updated: 6/6/25]
I decided to go back to basics and refresh my Linux knowledge. Here I'm recapping everything I've learnt.
I created a docker container running Ubuntu to practice using:
docker run -dit --name linux-learning --hostname ubuntu-dev --restart unless-stopped --cpus="2" --memory="4g" --mount type=bind,source="C:/ubuntu-data",target=/data -v /var/run/docker.sock:/var/run/docker.sock -p 2222:22 -p 8080:80 --env TZ=Europe/London --env LANG=en_GB.UTF-8 ubuntu:latest /bin/bash
Some important directories
/sbin -> System binaries for administrative commands
/bin -> Essential user binaries
/lib -> Shared libraries and kernel modules
/boot -> Stores files needed for booting the system
/usr -> Contains most user-installed applications and libraries.
/var -> Stores logs, caches, and temporary files that change frequently.
/etc -> Stores system configuration files.
/opt -> Used for installing optional third-party software
Understanding User Management
Creating users
There are 2 ways you can create a new user: useradd or adduser
useradd
-> Directly modifies system files like /etc/passwd, /etc/shadow, and /etc/group to create a new user but you need to specify all options manually and by default it doesn't create a home directory unless you specify the -m flag. You also have to manually set the password for the new user using the passwd command after creating the user. Useful when writing scripts as it doesn't prompt for additional details.
adduser
-> It provides a user-friendly, interactive experience by prompting you to enter a password and additional user details like full name, phone, etc. It automatically creates the home directory and uses configuration from /etc/adduser.conf for defaults.
In my case this command wasn't available by default and I had to install it using apt install adduser
. You can check if you have it installed in /sbin
To see which users have been created you can check the /etc/passwd file
.
User passwords are encrypted and stored in the etc/shadow
file. Passwords cant be decrypted once created but can be reset using sudo passwd username.
Switching users
When switching to another user you can use either su username
or su - username
.
su username
allows you to become that user but keep your current environment such as paths and variables and is useful for quick command execution.
su - username
means you fully switch to the other user's environment including their paths, shell settings and any startup scripts.
Groups
Groups are used to organise users and manage permissions their collectively.
groupadd
-> to create a new group
cat /etc/group
-> to view groups
usermod -aG groupname username
-> to add a user to a group
gpasswd -d username groupname
-> to remove a user from a group
Top comments (0)