You are on page 1of 2

Ubuntu Server CLI pro tips

Networking Packages Files


BASIC

Get the IP address of all interfaces Search for packages List files Create directories recursively
networkctl status apt search <string> ls mkdir -p <directory1>/<directory2>
snap find <string>
Display all IP addresses of the host List files with permissions and dates Delete a directory recursively
List available updates ls -al rm -r <directory>
hostname -I
apt list --upgradable
Enable/disable interface Apply all available updates Common file operations Quick file search
ip link set <interface> up create empty: touch <filename> locate <q>
sudo apt update && sudo apt upgrade
ip link set <interface> down create with content: echo "<content>" > <filename>
Install from the Ubuntu archive: append content: echo "<content>" >> <filename> Search string in file
Manage firewall rules sudo apt install <package> display a text file: cat <file> grep <string> <filename>
enable firewall: sudo ufw enable copy: cp <file> <target filename>
Install from the snap store: move/rename: mv <file> <target directory/filename> Search string recursively in
list rules: sudo ufw status sudo snap install <package> directory
delete: rm <file>
allow port: sudo ufw allow <port> grep -Iris <string> <directory>
deny port: sudo ufw deny <port> Which package provides this file? Create a directory
sudo apt install apt-file mkdir <directory>
Connect remotely through SSH sudo apt-file update
ssh <user>@<host IP> apt-file <filename or command>

Security Ubuntu release cadence


Show which users are logged in Automatically detect and ban
w abusive IP addresses Ubuntu 20.04 LTS
Get password expiration date for sudo apt install fail2ban
Ubuntu 19.10
<user> Show banned IP addresses
chage -l <user> Ubuntu 19.04
sudo fail2ban-client status
sudo fail2ban-client status <jail> Ubuntu 18.04 LTS
Set password expiration
date for <user> Get the support status for installed
Ubuntu 16.04 LTS
sudo chage <user> packages Ubuntu 14.04 LTS

Lock a user account ubuntu-support-status


2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031
sudo passwd -l <user> Enable kernel live patching
sudo snap install canonical-livepatch Hardware and maintenance updates Interim release
Unlock a user account
sudo canonical-livepatch enable <token> Maintenance updates Extended security maintenance for customers
sudo passwd -u <user>

List open ports and associated Visit ubuntu.com/livepatch to get a


processes free token for up to 3 machines.
sudo netstat -tulpn
2020
Ubuntu Server CLI pro tips
Files Kubernetes and containers
ADVANCED

Find files modified in the last n minutes Pack a directory into an archive Install MicroK8s and list available add-ons Or another distro
find <directory> -mmin -<n> -type f
 zip: zip -r <target> <source dir> sudo snap install microk8s --classic lxc launch images:centos/8/amd64
eg. find . -mmin -5 -type f tar.gz: tar cvzf <target>.tar.gz <source dir> microk8s.status --wait-ready <container name>

Show only the nth column Unpack an archive Enable a MicroK8s add-on Get a shell inside a LXD container
col<n> “<separator>” <filename> zip: unzip <zip file> microk8s.enable <service> lxc exec <name> -- /bin/bash
eg. col2 “,” foo.csv tar.gz: tar xf <tar.gz file>
View MicroK8s nodes and running services Push a file to a LXD container
Display file paginated Copy file to remote server microk8s.kubectl get nodes
 lxc file push <filename>
less <filename> scp <filename> <user@server>:<destination> microk8s.kubectl get services <container name>/<path>
eg. scp config.yaml admin@192.0.0.0:/config  
Display first n lines More MicroK8s help at microk8s.io/docs Pull a file from a LXD container
head -n <n> <filename> Copy directory recursively lxc file pull <destination>
from remote server Launch a LXD container <container name>/<file path>
Display last n lines scp -r <user@server>:<source> <destination> lxd init
tail -n <n> <filename> eg. scp -r admin@192.0.0.0:/config /tmp lxc launch ubuntu:18.04 <container name> More LXD help at linuxcontainers.org/lxd

Follow file content as it increases


tail -f <filename> Virtualisation
Install Multipass and launch List existing VMs
System an Ubuntu VM multipass list
sudo snap install multipass --classic
Display kernel version Get the list of recent logins multipass launch <image> --name <VM name> Get a shell inside a VM
uname -r last multipass shell <VM name>
Omitting <image> will launch a VM with
Get disk usage Display running processes the latest Ubuntu LTS More Multipass help at
df -h htop discourse.ubuntu.com
Find available images
Get memory usage Kill process by id multipass find
cat /proc/meminfo kill <process id>

Get system time Kill process by name


timedatectl status pkill <process name> OpenStack
Set system timezone Run command in the background Install OpenStack and launch
timedatectl list-timezones <command> & an instance
sudo timedatectl set-timezone <zone> sudo snap install microstack --classic
Display background commands sudo microstack.init
Get all running services jobs microstack.launch
systemctl --state running
Bring command <n> to the foreground The Horizon dashboard is available at 10.20.20.1
Start or stop a service fg <n> Default credentials: admin / keystone
service <service> start/stop
More MicroStack help at microstack.run/docs
2020

Monitor new logs for a service


journalctl -u <service> --since now -f

You might also like