linux-commands

list of common linux command i use when i setup Ubuntu server

permissions

image

list ports with pid

lsof -i

reboot

sudo shutdown -r now

user

create

adduser username
passwd username
deluser --remove-home username

add to group

getent group
usermod -a -G group1,group2 username

add user to all default groups (kvm servers):

usermod -a -G root,daemon,bin,sys,adm,tty,disk,lp,mail,news,uucp,man,proxy,kmem,dialout,fax,voice,cdrom,floppy,tape,sudo,audio,dip,www-data,backup,operator,list,irc,src,gnats,shadow,utmp,video,sasl,plugdev,staff,games,users,nogroup,systemd-journal,systemd-network,systemd-resolve,systemd-timesync,crontab,messagebus,input,kvm,render,syslog,tss,uuidd,tcpdump,ssh,landscape,admin,netdev,lxd,systemd-coredump username

DNS

dns are in the following path:

/etc/resolv.conf

or in :

/etc/netplan

docker

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

php

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt upgrade
sudo apt update
sudo apt install php php-cli php-common
sudo apt install openssl php-curl php-mbstring php-mysql php-xml php-zip php-gd php-readline php-tokenizer

composer

cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

laravel sail

alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
sail up -d

webserver

start apache

sudo service apache2 start

stop nginx

sudo systemctl stop nginx

disable nginx from startup

sudo systemctl disable nginx

laravel config

<VirtualHost *:80>
   ServerName thedomain.com
   ServerAdmin webmaster@thedomain.com
   DocumentRoot /var/www/html/example/public

   <Directory /var/www/html/example>
       AllowOverride All
   </Directory>
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

enable rewrite module in apache

sudo a2enmod rewrite

mysql

install mysql

sudo apt-get install mysql-server

enter mysql server for the first time

sudo mysql

change default password mysql (sql command)

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

mysql create database

CREATE DATABASE db_name;

mysql create user

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'sammy'@'localhost' WITH GRANT OPTION;

php my admin

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

Timezone

check current timezone

date

change the timezone

sudo timedatectl set-timezone <your_time_zone>

VPN server

Orginal x-ui installation

default port is 54321

sudo bash < <(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)

English version x-ui installation

sudo bash < <(curl -Ls https://raw.githubusercontent.com/hossinasaadi/x-ui/master/install.sh)