Linux Commands Reference

We publish these commands for our developer’s for reference purposes. They are publicly visible as it might be helpful for other users as well:

Docker

#stop all containers:
docker stop $(docker ps -a -q)

# Restart docker service
sudo systemctl restart docker.service

#stop all containers by force
docker kill $(docker ps -q)

#remove all containers
docker rm $(docker ps -a -q)

#remove all docker images
docker rmi $(docker images -q)

#purge the rest
docker system prune --all --force --volumes

Error response: Could not kill running container runc did not terminate successfully: container_linux.go:392: init process caused “permission denied”

This can happen if apparmor prevents stopping the docker container.
One solution is to uninstall apparmor and restarting the docker service:

sudo apt-get purge --auto-remove apparmor
sudo service docker restart
docker system prune --all --volumes

sudo systemctl restart docker
sudo systemctl daemon-reload

Error starting userland proxy: listen tcp 172.200.0.1:443: bind: address already in use

Find PID and kill it:

sudo netstat -nlpt |grep 3306

sudo kill [pid]

 

Network

Number of open connections per ip
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n

Show all connected ip addresses to a certain port
netstat -an |grep 443
netstat -an |grep 80

Count connections per IP
netstat -an | grep 80 | wc -l
netstat -an | grep 443 | wc -l

Firewall iptables

Firewall Block IP Adress
sudo iptables -A INPUT -s [IP ADDRESS] -j DROP

Allow access from a specific IP address
sudo iptables -A INPUT -s 91.52.78.249 -p tcp –destination-port 3306 -j ACCEPT

Firewall Rules
See: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04

  • sudo ufw default deny incoming
  • sudo ufw default allow outgoing
  • sudo ufw allow ssh
  • sudo ufw allow 1000
  • sudo ufw allow http
  • sudo ufw allow 443
  • sudo ufw allow from 91.52.78.249 to any port 3306 (Local IP address)
  • sudo ufw allow from 52.45.200.92 to any port 3306 (Amazon DBS)
  • sudo ufw deny from 157.245.247.135

MySQL

Change MySQL password authentication module tomysql_native_password.

Needed for upgrading from 7.X to mysql 8.x

ALTER USER ‘user’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password1’;