Linux command

show ubuntu version

cat /etc/issue

Update Ubuntu

sudo apt-get update -y
sudo apt update
sudo apt upgrade -y

monitor port

sudo netstat -tualpn
sudo netstat -tualp

apache default file location

/etc/apache2

apache default html location

/var/www/html

include other packages which is not in the default, like python3.7

sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa

ssh connect to gcp

ssh -i ~/.ssh/id_rsa erichung@34.80.82.196

environment variable

default:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

Method 1. copy file to

/usr/bin

Method 2. add path to

/etc/environment

內網滲透

brew install ngrok #or snap install ngrok
ngrok config add-authtoken 2KQDERnnUjddPsWNMRhr3vsUeR1_3akBvNWQbgAMKNY8mH9ft
ngrok http <port>

安裝python3.8及pip3.8

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.8 python3.8-distutils -y
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py
export PATH=$PATH:/home/<your username>/.local/bin

find and replace in vim

vim 會將檔案內的所有的“search_from”字串替換成“replace_to”字串

:%s/search_from/replace_to/g

關閉與開啟自動換行

:set nowrap
:set wrap

Change Password

passwd

Search all ip

fping -a -g 10.187.96.0/24

copy file to ssh server

scp [file] [username]@[ip address]:[destination path]

WireGuard

sudo wg-quick up judge

kill background program

ps -eaf | grep cmsResourceService

Add iptable rule

sudo iptables -A INPUT -p tcp --dport 8888 -j ACCEPT

only allow specific IP and Ports

sudo iptables -A INPUT -p tcp --dport 8888:8890 -s 140.116.0.0/16 -j ACCEPT

start ssh

sudo apt install openssh-server
systemctl enable ssh.service
sudo systemctl start sshd.service

brew package location

/opt/homebrew/Cellar

Only can create, can't delete

sudo chattr -a tmp

change website contents (Developer Mode)

document.designMode='on'

bits/stdc++.h path on mac

/Library/Developer/CommandLineTools/SDKs/MacOSX[MaxOS Version].sdk/usr/include/c++/v1/bits

or

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/bits
stdc++.h
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

Sent Message to all user

wall "message"

Sent Message to individual user

write [user name]

use who to show pts index

echo -e "Hello World.\n" > /dev/pts/7

Deny Message

mesg n
# mesg y

sync freeBSD time

sudo ntpdate -b tw.pool.ntp.org

string cut

use ' ' to separate strings , and get only the first phrase

cut -d ' ' -f 1

Show the top 30 largest files by capacity of each user

sudo du -h /home/* | sort -rh | head -n 30

share your terminal

curl -sSf https://sshx.io/get | sh && sshx

Enable SSH Service

sudo apt install openssh-server
sudo systemctl enable ssh
sudo ufw allow ssh

Python http server

python -m http.server

Execute one-time commands "at" a specified time

sudo at 14:50 2024-02-04
[command]
Ctrl+D

synchronize time to Taiwan time zone

sudo timedatectl set-timezone Asia/Taipei

Show all listening port

netstat -tln

show public ip

curl ifconfig.me

Remove all python packages

pip freeze | xargs pip uninstall -y

add github config

git config --global user.name erichung9060
git config --global user.email rthung96@gmail.com

change python version

ls /usr/bin/python3*



sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1

sudo update-alternatives --remove python3 /usr/bin/python3.9

sudo update-alternatives --config python3