Skip to main content
In this lesson we’ll cover Linux security basics focused on access control: user accounts, groups, file ownership and permissions, and privilege escalation. You’ll learn how to create and manage users, inspect account details, and switch identities safely using su and sudo. Each topic includes commands and examples so you can practice these essential administrative skills.
A presentation slide titled "Security and File Permissions" with the KodeKloud logo. It shows topic boxes like "Basic Security and Identifying File Types," "Creating Users and Groups," "Managing file permission and ownership," and highlighted lab items such as "Labs: Special Directories and Files."
Security in Linux spans many layers:
  • Authentication (who you are) — often handled via passwords, keys, and frameworks such as PAM (Pluggable Authentication Modules).
  • Access control (what you can do) — user and group permissions, file modes, ACLs, and mandatory access controls such as SELinux.
  • Network and service protection — firewalling (iptables, nftables, firewalld), SSH hardening, and service isolation.
  • Audit and accountability — centralized logs, sudo logs, and system accounting.
This lesson focuses on the basics: user and group accounts, how user metadata is stored, and how to escalate or switch privileges safely. For deeper reading:
A slide titled "Linux Accounts" showing a central "Linux Security" box connected to components like Access Controls, PAM, Network Security, SSH Hardening, SELinux, and "Many More." The slide is branded with the KodeKloud logo.

What is a user account?

A Linux user account represents an identity that can authenticate and perform actions on the system. Each account stores metadata used by the kernel and system services to control access. Typical account fields:
  • username
  • password placeholder (usually an x in /etc/passwd, with the hashed password in /etc/shadow)
  • UID (user ID) — unique integer
  • primary GID (group ID)
  • optional comment / GECOS (human-readable info)
  • home directory
  • default login shell
Account and group data are stored in:
  • /etc/passwd — account metadata and login shell/home
  • /etc/shadow — encrypted password hashes (restricted)
  • /etc/group — groups and group members
Example: two developers (bob and michael) can be members of the same group (e.g., developers) to share access to common files. Example contents of /etc/passwd and /etc/group:

Account field breakdown (quick reference)

Inspect a user’s IDs and groups:
Check a user’s home and shell by reading /etc/passwd (see example above).

Account types

  • User account — for a person who needs access.
  • Superuser (root) — UID 0; unrestricted privileges.
  • System accounts — created for OS services; often have low UIDs and no interactive shell.
  • Service accounts — created for specific applications (e.g., nginx, mysql).
A presentation slide titled "Account Types" showing four colored boxes for User Account, Superuser Account (UID = 0), System Accounts (with UID ranges), and Service Accounts, plus example usernames (e.g., Bob, root, ssh, nginx). The slide includes the KodeKloud logo and illustrative icons.
Examples:

Switching users: su vs sudo

There are multiple ways to run commands as another user. Choose the method that fits your operational and auditing requirements.

su (substitute user)

  • su starts a shell as another user and typically requires the target user’s password.
  • su - opens a login shell, loading the target user’s environment.
  • Useful for interactive sessions, but less auditable because commands aren’t centrally logged by sudo.
Examples:

sudo (delegate privileges)

  • sudo lets authorized users run commands as another user (commonly root) by authenticating with their own password.
  • Sudo policies are configured in /etc/sudoers and in files under /etc/sudoers.d/.
  • sudo provides better auditing and fine-grained privilege delegation.
Example usage:
Sample /etc/sudoers (simplified):
Always use visudo to edit /etc/sudoers. visudo locks the file and checks for syntax errors before saving, preventing misconfiguration that could lock out administrative access.
Sudo examples of delegation:
  • Grant full root access to a user: username ALL=(ALL:ALL) ALL
  • Grant a group limited privileges: %developers ALL=(ALL) /usr/bin/systemctl restart myservice

Best practice: avoid direct root logins

  • Disable direct root SSH access (set PermitRootLogin no in /etc/ssh/sshd_config).
  • Encourage administrators to use sudo for privilege escalation. This enables accountability, because sudo logs which user ran which command.

Summary and next steps

  • User and group accounts are the foundation of Linux access control. Their metadata lives in /etc/passwd and /etc/group.
  • Use id, who, and last to inspect accounts and sessions.
  • Prefer sudo over su for privilege escalation because sudo is auditable and configurable.
  • Edit sudoers only with visudo to avoid syntax errors.
  • Practice creating users, placing them in groups, and configuring sudo policies in a lab environment.
Further references: Practice exercises (suggested):
  • Create two users, add them to a shared group, and verify file permissions for group members.
  • Configure a sudo rule that allows a non-root user to run a single administrative command.
  • Disable direct root SSH access and confirm you can still perform administrative tasks using sudo.

Watch Video