Ubuntu Linux – Handy stuff

Update all packaged :  $ sudo apt-get update

Upgrade all packages: $ sudo apt-get upgrade

What’s my Machine name and Linux Version

$ > hostname

$ > cat /etc/os-release

What’s my Private IP

$ > hostname -i

$ > hostname -I |'{print $1}’

$ > ip route get 1.2.3.4 | awk ‘{print $7}’

What’s my Public IP

curl ifconfig.me   or ifconfig.co

dig +short myip.opendns.com @resolver1.opendns.com

What’s my Username

$ > whoami

Show my network interfaces

nmcli -p device show

nmcli device show

Fix Broken Packages: $ sudo dpkg –configure -a // Fix any broken pkgs

Install a package say iputils-ping and 

$ > apt-get update && apt-get install -y iputils-ping \

Uninstall a package: $ sudo apt remove azure-cli -y && sudo apt autoremove -y

To see Long description of each package: $ apt show package_name       E.g. apt show php-cli

sudo apt install lynx  // text based browser on linux.

USEFUL Packages:

  • For Admin: netstat, iputils-ping, webmin
  • For Dev work: nodejs, npm, azure-cli, lynx (text browser), pwsh,  pluma (text editor)

Networking and firewalls

  • Which processes are listening on 443 (ssl): $ sudo netstat -tulpn | grep :443
  • Show firewall rules: sudo ufw app list sudo ufw app info “Apache Full”

Install Azure-cli with one command: $ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Search for a string in multiple files:

grep -i -r “/opt/bitnami/apps/wordpress” /opt/*  // Searching for the string “/opt/bitnami/apps/wordpress” in all files/subfolders under /opt

https://www.cyberciti.biz/faq/howto-recursively-search-all-files-for-words/

Add SWAP File: 

sudo fallocate -l 2G /swapfile

sudo chmod 600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

sudo nano /etc/fstab

Paste this line at end of file: /swapfile swap swap defaults 0 0

Verify swap is on: sudo swapon –show

Check free swap space: sudo free -h

Configure swappiness:

cat /proc/sys/vm/swappiness

Output : 60

Temporarily change it:

sudo sysctl vm.swappiness=10

Permanently change it to survive reboots:

sudo nano /etc/sysctl.conf

Add this line into file: vm.swappiness=10

 

Remove swap file and virtual memory: (ONLY if needed, we generally want swap)

sudo swapoff -v /swapfile

remove the swap file entry /swapfile swap swap defaults 0 0 from the /etc/fstab file

Then remove the swap file: sudo rm /swapfile

 

Install Webmin:  https://localhost:10000/

sudo nano /etc/apt/sources.list

> Add this line to end of file:  deb https://download.webmin.com/download/repository sarge contrib

Press Ctrl O to save file. > Press Ctrl X to exit editor

OR simply do $ sudo su and then

$ sudo echo “deb https://download.webmin.com/download/repository sarge contrib” >>  /etc/apt/sources.list

$ wget -q -O- http://www.webmin.com/jcameron-key.asc | sudo apt-key add

$ sudo apt update && sudo dpkg –configure -a // Fix any broken pkgs

$ sudo apt install webmin // Install Webmin..

$ sudo /etc/init.d/webmin restart  // works better to restart webmin

If error see command to run – Webmin server cannot be started. It is advised to start it manually

by running “/etc/webmin/restart-by-force-kill” command

On WSL the sudo and webmin username/password is same as your windows username/password..

Find username on webmin trick (run the command below as is, it outputs the needed uid)

$ sudo /usr/share/webmin/changepass.pl /etc/webmin username password

ISSUE: Webmin Access denied multiple authentication attempts  (note the IP denied in error shown)

FIX: sudo nano /etc/webmin/miniserv.conf  (or do sudo su first if access denied)

  • Add line anywhere:  allow=2.30.221.4    (specify the IP denied here) 
  • Ctrl O and Ctrl X (save and exits)

or sudo echo “allow=127.0.0.1” >> /etc/webmin/miniserv.conf

sudo /etc/init.d/webmin restart

ALT Install method for Webmin:

mkdir downloads && cd downloads

wget https://prdownloads.sourceforge.net/webadmin/webmin-1.962.tar.gz

sudo apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python

tar -xzvf webmin-1.997.tar.gz

cd webmin-1.997    (or 1.962)

sudo sh setup.sh

==============================

 

Leave a Reply