🐋Linux

The Basics

Basic commands
  • sudo apt update && sudo apt upgrade -y

  • sudo apt install net-tools

Systemctl
  • sudo systemctl restart <systemd-process-name>

  • sudo systemctl stop <systemd-process-name>

  • sudo systemctl status <systemd-process-name>

  • sudo journalctl -f -u <systemd-process-name>

  • sudo systemctl enable /etc/systemd/system/<systemd-process-name>

  • sudo systemctl disable /etc/systemd/system/<systemd-process-name>

Linux user
  • sudo chown -R ubuntu:ubuntu /var/www

  • sudo visudo ubuntu ALL=(ALL) NOPASSWD:ALL

Find, files
  • find . -mount -type f -size +1G 2>/dev/null

  • find . -mount -type f -size +100M 2>/dev/null

  • sudo du -a / | sort -n -r | head -n 20

Important! When you enable Firewall and if you want to connect on your server by ssh, you must allow it in firewall 22 port

Firewall
  • sudo ufw status

  • sudo ufw enable

  • sudo ufw disable

  • sudo ufw allow OpenSSH

  • sudo ufw allow 22

  • sudo ufw allow 22/tcp

  • sudo ufw allow 3306

  • sudo ufw allow 'Nginx HTTP'

  • sudo ufw app list

Remote connection
  • scp readme.txt user@192.168.0.1:/home/user/temp

  • scp -r -i ~/.ssh/digitalocean readme.txt user@192.168.0.1:/home/user/temp

Configs
  • wget -qO- eth0.me - get ip server

  • ifconfig | grep "inet " | grep -v 127.0.0.1 - To get access to your localhost you can via using same wifi network

  • ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' - Get your local IP

Crontab

Useful link

  • 0 * * * * - Every hour

Aliases

Add alias:

sudo nano ~/.bashrc alias p='df -h'

Gpg keys

Install gpg command

  • gpg --full-gen-key - generate key

All keys in ~/.gnupg/openpgp-revocs.d/

Ssh

Create ssh key and paste it in server:

  1. ssh-keygen -t rsa - generate an ssh key (type file path and name if you want)

  2. Or ssh-keygen -t rsa -f ~/.ssh/example - generate an ssh key (type file path and name if you want)

  3. pbcopy < ~/.ssh/id_rsa.pub - copy file contents

  4. Paste .pub content to server

Connection to server:

ssh <username>@<ip_address> 
ssh <username>@<ip_address> -i ~/.ssh/id_rsa

  • sudo lsof -i -P | grep LISTEN | grep :$PORT - Check all ports

Last updated