Ubuntu Server CLI pro tips

BASIC

Ubuntu Server CLI pro tips

Networking

Packages

Files

Get the IP address of all interfaces

Search for packages

List files

networkctl status

Display all IP addresses of the host

hostname -I

Enable/disable interface

ip link set up

ip link set down

Manage firewall rules

enable firewall: sudo ufw enable

list rules: sudo ufw status

allow port: sudo ufw allow

deny port: sudo ufw deny

Connect remotely through SSH

ssh @

apt search

snap find

mkdir -p /

List files with permissions and dates

Delete a directory recursively

ls -al

rm -r

Common file operations

Quick file search

locate

sudo snap install

create empty: touch

create with content: echo "" >

append content: echo "" >>

display a text file: cat

copy: cp

move/rename: mv

delete: rm

Which package provides this file?

Create a directory

List available updates

apt list --upgradable

Apply all available updates

sudo apt update && sudo apt upgrade

Install from the Ubuntu archive:

sudo apt install

Install from the snap store:

sudo apt install apt-file

sudo apt-file update

apt-file

Security

Show which users are logged in

w

2020

Automatically detect and ban

abusive IP addresses

sudo apt install fail2ban

chage -l

sudo fail2ban-client status

sudo fail2ban-client status

Show banned IP addresses

sudo chage

Get the support status for installed

packages

Lock a user account

ubuntu-support-status

sudo passwd -l

Enable kernel live patching

Unlock a user account

sudo passwd -u

sudo snap install canonical-livepatch

sudo canonical-livepatch enable

List open ports and associated

processes

Visit livepatch to get a

free token for up to 3 machines.

sudo netstat -tulpn

Search string in file

grep

Search string recursively in

directory

grep -Iris

mkdir

Ubuntu release cadence

Get password expiration date for

Set password expiration

date for

Create directories recursively

ls

Ubuntu 20.04 LTS

Ubuntu 19.10

Ubuntu 19.04

Ubuntu 18.04 LTS

Ubuntu 16.04 LTS

Ubuntu 14.04 LTS

2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031

Hardware and maintenance updates

Maintenance updates

Interim release

Extended security maintenance for customers

ADVANCED

Ubuntu Server CLI pro tips

Kubernetes and containers

Files

Find files modified in the last n minutes

Pack a directory into an archive

Or another distro

lxc launch images:centos/8/amd64

Unpack an archive

Enable a MicroK8s add-on

Get a shell inside a LXD container

zip: unzip

tar.gz: tar xf

microk8s.enable

lxc exec -- /bin/bash

Display file paginated

Copy file to remote server

View MicroK8s nodes and running services

Push a file to a LXD container

less

scp :

eg. scp config.yaml admin@192.0.0.0:/config??

microk8s.kubectl get nodes

microk8s.kubectl get services

lxc file push

/

More MicroK8s help at microk8s.io/docs

Pull a file from a LXD container

Launch a LXD container

lxc file pull

/

zip: zip -r

tar.gz: tar cvzf .tar.gz

Show only the nth column

col ¡°¡±

eg. col2 ¡°,¡± foo.csv

Display first n lines

head -n

Display last n lines

tail -n

Copy directory recursively

from remote server

scp -r :

eg. scp -r admin@192.0.0.0:/config /tmp

Follow file content as it increases

lxd init

lxc launch ubuntu:18.04

tail -f

Virtualisation

System

Install Multipass and launch

an Ubuntu VM

Display kernel version

Get the list of recent logins

uname -r

last

sudo snap install multipass --classic

multipass launch --name

Get disk usage

Display running processes

df -h

htop

Get memory usage

Kill process by id

cat /proc/meminfo

kill

Get system time

Kill process by name

timedatectl status

pkill

Set system timezone

Run command in the background

timedatectl list-timezones

sudo timedatectl set-timezone

&

Get all running services

jobs

systemctl --state running

Start or stop a service

2020

Install MicroK8s and list available add-ons

sudo snap install microk8s --classic

microk8s.status --wait-ready

find -mmin - -type f

eg. find . -mmin -5 -type f

service start/stop

Monitor new logs for a service

journalctl -u --since now -f

Display background commands

Bring command to the foreground

fg

Omitting will launch a VM with

the latest Ubuntu LTS

More LXD help at lxd

List existing VMs

multipass list

Get a shell inside a VM

multipass shell

More Multipass help at

discourse.

Find available images

multipass find

OpenStack

Install OpenStack and launch

an instance

sudo snap install microstack --classic

sudo microstack.init

microstack.launch

The Horizon dashboard is available at 10.20.20.1

Default credentials: admin / keystone

More MicroStack help at microstack.run/docs

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download