Useful Linux Command Line Stuff: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m →Files |
||
Line 45: | Line 45: | ||
:<code>sudo apt-file update</code> | :<code>sudo apt-file update</code> | ||
:<code>apt-file <filename or command></code> | :<code>apt-file <filename or command></code> | ||
==Security== | ==Security== |
Revision as of 12:46, 10 July 2024
Most of the Information below is from the 2020 Canonical Ubuntu Server Pro Tips guide (no longer available)
Note that some shells and distributions may vary in their syntax and so some commands may not work or be available (by default). Always read the relevant documentation for your distro before working on a live machine.
Networking
Get the IP address of all interfaces
networkctl status
Display all IP addresses of the host
hostname -I
Enable/disable interface
ip link set <interface> up
ip link set <interface> down
Manage firewall rules
- enable firewall:
sudo ufw enable
- list rules:
sudo ufw status
- allow port:
sudo ufw allow <port>
- deny port:
sudo ufw deny <port>
Connect remotely through SSH
ssh <user>@<host IP>
Packages
Search for packages
apt search <string>
snap find <string>
List available updates
apt list --upgradable
Apply all available updates
sudo apt update && sudo apt upgrade
Install from the Ubuntu archive:
sudo apt install <package>
Install from the snap store:
sudo snap install <package>
Which package provides this file?
sudo apt install apt-file
sudo apt-file update
apt-file <filename or command>
Security
Show which users are logged in
w
Get password expiration date for <user>
chage -l <user>
Set password expiration date for <user>
sudo chage <user>
Lock a user account
sudo passwd -l <user>
Unlock a user account
sudo passwd -u <user>
List open ports and associated processes
sudo netstat -tulpn
Automatically detect and ban abusive IP addresses
sudo apt install fail2ban
Show banned IP addresses
sudo fail2ban-client status
sudo fail2ban-client status <jail>
Get the support status for installed packages
ubuntu-support-status
Enable kernel live patching:
sudo snap install canonical-livepatch
sudo canonical-livepatch enable <token>
Visit ubuntu.com/livepatch to get a free token for up to 3 machines.
System
Display kernel version
uname -r
Get disk usage
df -h
Get memory usage
cat /proc/meminfo
Get system time
timedatectl status
Set system timezone
timedatectl list-timezones
sudo timedatectl set-timezone <zone>
Get all running services
systemctl --state running
Start or stop a service
service <service> start/stop
Monitor new logs for a service
journalctl -u <service> --since now -f
System
Display kernel version
uname -r
Get disk usage
df -h
Get memory usage
cat /proc/meminfo
Get system time
timedatectl status
Set system timezone
timedatectl list-timezones
sudo timedatectl set-timezone <zone>
Get all running services
systemctl --state running
Start or stop a service
service <service> start/stop
Monitor new logs for a service
journalctl -u <service> --since now -f
Kubernetes and containers
Install MicroK8s and list available add-ons
sudo snap install microk8s --classic
microk8s.status --wait-ready
Enable a MicroK8s add-on
microk8s.enable <service>
View MicroK8s nodes and running services
microk8s.kubectl get nodes
microk8s.kubectl get services
Launch a LXD container
lxd init
lxc launch ubuntu:18.04 <container name>
Or another distro
lxc launch images:centos/8/amd64 <container name>
Get a shell inside a LXD container
lxc exec <name> -- /bin/bash
Push a file to a LXD container
lxc file push <filename> <container name>/<path>
Pull a file from a LXD container
lxc file pull <destination> <container name>/<file path>
Virtualisation
Install Multipass and launch an Ubuntu VM
sudo snap install multipass --classic
multipass launch <image> --name <VM name>
- Omitting <image> will launch a VM withthe latest Ubuntu LTS
Find available images
multipass find
List existing VMs
multipass list
Get a shell inside a VM
multipass shell <VM name>
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
- The Horizon dashboard is available at