<<

CLI pro tips

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

Security Ubuntu release cadence

Show which users are logged in Automatically detect and ban w abusive IP addresses buntu . sudo apt install fail2ban Get password expiration date for bnt 0 Show banned IP addresses bnt 0 chage -l sudo fail2ban-client status buntu . Set password expiration sudo fail2ban-client status buntu . date for Get the support status for installed sudo chage packages buntu . Lock a user account ubuntu-support-status 20 20 20 20 20 20 2020 202 2022 202 202 202 202 202 202 202 200 20 sudo passwd -l Enable kernel live patching Unlock a user account sudo snap install -livepatch ardare and maintenance pdates Interim release sudo passwd -u sudo canonical-livepatch enable Maintenance pdates Etended secrity maintenance for cstomers 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 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 -mmin - -type f zip: zip -r sudo snap install microk8s --classic launch images:/8/amd64 eg. find . -mmin -5 -type f t a r.g z: tar cvzf .tar.gz microk8s.status --wait-ready Show only the nth column Unpack an archive Enable a MicroK8s add-on Get a shell inside a LXD container

ADVANCED col zip: unzip microk8s.enable lxc exec -- /bin/ eg. col2 “,” foo.csv t a r.g z: tar xf 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 less scp : microk8s.kubectl get services / eg. scp config.yaml [email protected]:/config Display first n lines More MicroK8s help at microk8s.io/docs Pull a file from a LXD container head -n Copy directory recursively lxc file pull from remote server Launch a LXD container / Display last n lines scp -r : lxd tail -n eg. scp -r [email protected]:/config /tmp lxc launch ubuntu:18.04 More LXD help at linuxcontainers.org/lxd Follow file content as it increases tail -f 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 --name Get a shell inside a VM -r last multipass shell Omitting 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 Get system time Kill process by name timedatectl status pkill OpenStack Set system timezone Run command in the background Install OpenStack and launch timedatectl list-timezones & an instance sudo timedatectl set-timezone sudo snap install microstack --classic Display background commands sudo microstack.init Get all running services jobs microstack.launch systemctl --state running Bring command to the foreground The Horizon dashboard is available at 10.20.20.1 Start or stop a service fg Default credentials: admin / keystone service start/stop More MicroStack help at microstack.run/docs Monitor new logs for a service journalctl -u --since now -f 2020