Ubuntu Cheatsheat
System
System Information
uname -a
- Displays all system informationhostnamectl
- Shows current hostname and related detailslscpu
- Lists CPU architecture informationtimedatectl status
- Shows system time
System Monitoring and Management
top
- Displays real-time system processeshtop
- An interactive process viewer (needs installation)df -h
- Shows disk usage in a human-readable formatfree -m
- Displays free and used memory in MBkill <process id>
- Terminates a process
Running Commands
[command] &
- Runs command in the backgroundjobs
- Displays background commandsfg <command number>
- Brings command to the foreground
Service Management
sudo systemctl start <service>
- Starts a servicesudo systemctl stop <service>
- Stops a servicesudo systemctl status <service>
- Checks the status of a servicesudo systemctl reload <service>
- Reloads a service’s configuration without interrupting its operationjournalctl -f
- Follows the journal, showing new log messages in real timejournalctl -u <unit_name>
- Displays logs for a specific systemd unit
Cron Jobs and Scheduling
crontab -e
- Edits cron jobs for the current usercrontab -l
- Lists cron jobs for the current user
Files
File Management
ls
- Lists files and directoriestouch <filename>
- Creates an empty file or updates the last accessed datecp <source> <destination>
- Copies files from source to destinationmv <source> <destination>
- Moves files or renames themrm <filename>
- Deletes a file
File Permissions and Ownership
chmod [who][+/-][permissions] <file>
- Changes file permissionschmod u+x <file>
- Makes a file executable by its ownerchown [user]:[group] <file>
- Changes file owner and group
Searching and Finding
find [directory] -name <search_pattern>
- Finds files and directoriesgrep <search_pattern> <file>
- Searches for a pattern in files
Archiving and Compression
tar -czvf <name.tar.gz> [files]
- Compresses files into a tar.gz archivetar -xvf <name.tar.[gz|bz|xz]> [destination]
- Extracts a compressed tar archive
Text Editing and Processing
nano [file]
- Opens a file in the Nano text editorcat <file>
- Displays the contents of a fileless <file>
- Displays the paginated content of a filehead <file>
- Shows the first few lines of a filetail <file>
- Shows the last few lines of a fileawk '{print}' [file]
- Prints every line in a file
Packages
Package Management (APT)
sudo apt install <package>
- Installs a packagesudo apt install -f --reinstall <package>
- Reinstalls a broken packageapt search <package>
- Searches for APT packagesapt-cache policy <package>
- Lists available package versionssudo apt update
- Updates package listssudo apt upgrade
- Upgrades all upgradable packagessudo apt remove <package>
- Removes a packagesudo apt purge <package>
- Removes a package and all its configuration files
Package Management (Snap)
snap find <package>
- Search for Snap packagessudo snap install <snap_name>
- Installs a Snap packagesudo snap remove <snap_name>
- Removes a Snap packagesudo snap refresh
- Updates all installed Snap packagessnap list
- Lists all installed Snap packagessnap info <snap_name>
- Displays information about a Snap package
Users & Groups
User Management
w
- Shows which users are logged insudo adduser <username>
- Creates a new usersudo deluser <username>
- Deletes a usersudo passwd <username>
- Sets or changes the password for a usersu <username>
- Switches usersudo passwd -l <username>
- Locks a user accountsudo passwd -u <username>
- Unlocks a user passwordsudo chage <username>
- Sets user password expiration date
Group Management
id [username]
- Displays user and group IDsgroups [username]
- Shows the groups a user belongs tosudo addgroup <groupname>
- Creates a new groupsudo delgroup <groupname>
- Deletes a group
Networking
Network Configuration
ip addr show
- Displays network interfaces and IP addressesip -s link
- Shows network statisticsss -l
- Shows listening socketsping <host>
- Pings a host and outputs results
Netplan Configuration
cat /etc/netplan/*.yaml
- Displays the current Netplan configurationsudo netplan try
- Tests a new configuration for a set period of timesudo netplan apply
- Applies the current Netplan configuration
Firewall Management
sudo ufw status
- Displays the status of the firewallsudo ufw enable
- Enables the firewallsudo ufw disable
- Disables the firewallsudo ufw allow <port/service>
- Allows traffic on a specific port or servicesudo ufw deny <port/service>
- Denies traffic on a specific port or servicesudo ufw delete allow/deny <port/service>
- Deletes an existing rule
SSH and Remote Access
ssh <user@host>
- Connects to a remote host via SSHscp <source> <user@host>:<destination>
- Securely copies files between hosts
LXD
LXD is a modern, secure and powerful tool that provides a unified experience for running and managing containers or virtual machines. Visit https://canonical.com/lxd for more information.
Basic Setup
lxd init
- Initializes LXD before first use
Creating Instances
lxc init ubuntu:22.04 <container name>
- Creates a lxc system container (without starting it)lxc launch ubuntu:24.04 <container name>
- Creates and starts a lxc system containerlxc launch ubuntu:22.04 <vm name> --vm
- Creates and starts a virtual machine
Managing Instances
lxc list
- Lists instanceslxc info <instance>
- Shows status information about an instancelxc start <instance>
- Starts an instancelxc stop <instance> [--force]
- Stops an instancelxc delete <instance> [--force|--interactive]
- Deletes an instance
Accessing Instances
lxc exec <instance> -- <command>
- Runs a command inside an instancelxc exec <instance> -- bash
- Gets shell access to an instance (if bash is installed)lxc console <instance> [flags]
- Gets console access to an instancelxc file pull <instance>/<instance_filepath> <local_filepath>
- Pulls a file from an instancelxc file push <local_filepath> <instance>/<instance_filepath>
- Pushes a file to an instance
Using Projects
lxc project create <project> [--config <option>]
- Creates a projectlxc project set <project> <option>
- Configures a projectlxc project switch <project>
- Switches to a project
Ubuntu Pro
Ubuntu Pro delivers 10 years of expanded security coverage on top of Ubuntu’s Long Term Support (LTS) commitment in addition to management and compliance tooling. Visit https://ubuntu.com/pro to register for free on up to five machines.
Activating Ubuntu Pro
sudo pro attach <token>
- Attaches your machine to Ubuntu Pro using a specific token
Managing Services
sudo pro status
- Displays the status of all Ubuntu Pro servicessudo pro enable <service>
- Enables a specific Ubuntu Pro servicesudo pro disable <service>
- Disables a specific Ubuntu Pro service
Extended Security Maintenance (ESM)
sudo pro enable esm-infra
- Activates Extended Security Maintenance for infrastructure packagessudo pro enable esm-apps
- Activates ESM for applications
Livepatch Service
sudo pro enable livepatch
- Enables the Livepatch service for kernel updates without rebooting
FIPS Mode
sudo pro enable fips
- Enables FIPS mode for strict cryptographic standards
Updating Configuration
sudo pro refresh
- Refreshes the Ubuntu Pro statesudo pro detach
- Detaches the machine from Ubuntu Pro, disabling all services