Linux

Download

Debian

https://cdimage.debian.org/debian-cd/current/amd64/bt-dvd/

Ubuntu

http://ftp.sjtu.edu.cn/ubuntu-cd/
http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/mini.iso ( Mirror only http://us.archive.ubuntu.com/ , need proxy, local DNS not working )
Debug: Console 4 or /var/log/syslog

Mirrors

http://mirrors.huaweicloud.com https://mirrors.tuna.tsinghua.edu.cn

Bash

https://www.gnu.org/software/bash/manual/bash.html
1
url=https://raw.githubusercontent.com/fzinfz/scripts/master/init.sh # alias & functions
2
source /dev/stdin <<< "$(curl -sS $url)"
3
4
set
5
-x debug
6
-T If set, any traps on DEBUG and RETURN are inherited
7
-o functrace/errtrace
8
9
shopt [-pqsu] [-o] [optname …]
10
-s: Enable (set) each optname.
11
-u: Disable (unset) each optname.
12
13
shopt -s expand_aliases # when the shell is not interactive
14
alias foo='...'
15
16
0: stdin; 1: stdout; 2: stderr # File descriptor
17
2>&1 >/dev/null
18
&>/dev/null
19
ssh-add 2>/dev/null
Copied!
https://git.savannah.gnu.org/cgit/bash.git/

tmux

1
ctrl+b x -> kill pane # /usr/share/doc/tmux/examples/screen-keys.conf
2
cat /usr/share/doc/tmux/examples/screen-keys.conf | grep '\bbind \w'
Copied!

Init

Level
Desc
0
Halt the system.
1
Single-user mode (for special administration).
2
Local Multiuser with Networking but without network service (like NFS)
3
Full Multiuser with Networking
4
Not Used
5
Full Multiuser with Networking and X Windows(GUI)
6
Reboot.
1
ls -R -l /etc/rc*
2
3
ls -l /usr/lib/systemd # check `systemd` page for more
4
ls -l /usr/share/upstart # last release 2014; 3 years ago
5
ls -l /etc/init.d # SysV init
6
7
cat /etc/modules-load.d/*
8
9
apt install systemd-sysv # make link: /sbin/init -> /lib/systemd/systemd
Copied!

login & non-login shells

https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
1
login shells:
2
/etc/profile
3
~/.bash_profile(?-> ~/.bashrc), ~/.bash_login, and ~/.profile
4
exit: ~/.bash_logout
5
6
non-login shells:
7
~/.bashrc
8
9
# echo $0 : `shopt login_shell` \| $-
10
-bash : login_shell on | himBHs
11
# bash
12
# echo $0 : `shopt login_shell` \| $-
13
bash : login_shell off | himBHs
14
# bash -c 'echo $0 : `shopt login_shell` \| $-'
15
bash : login_shell off | hBc
Copied!

supervisord

http://supervisord.org/running.html

Exit code

http://tldp.org/LDP/abs/html/exitcodes.html
1
1 Catchall for general errors
2
2 Misuse of shell builtins
3
126 Command invoked cannot execute
4
127 "command not found" illegal_command Possible problem with $PATH or a typo
5
128+n Fatal error signal "n"
6
kill -9 $PPID of script $? returns 137 (128 + 9)
7
130 Script terminated by Control-C
Copied!

Syslog Message Severities

https://tools.ietf.org/html/rfc5424#section-6.2.1
1
0 Emergency: system is unusable
2
1 Alert: action must be taken immediately
3
2 Critical: critical conditions
4
3 Error: error conditions
5
4 Warning: warning conditions
6
5 Notice: normal but significant condition
7
6 Informational: informational messages
8
7 Debug: debug-level messages
Copied!

Signals

1
kill -l
2
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
3
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL ... 64) SIGRTMAX
Copied!

kill

1
pkill -KILL -u {username}
Copied!

top

1
* 1 - Single Cpu Off (thus multiple cpus)
2
* c - Command line Off (name, not cmdline)
3
* i - Idle tasks On (show all tasks)
4
j - Str align right Off (not right justify)
5
V - Forest view On (show as branches)
6
f - sort/hide columns
7
(`*') could be overridden through the command-line.
Copied!

Glances - A top/htop alternative - Python

https://github.com/nicolargo/glances
1
pip install glances[action,browser,cloud,cpuinfo,chart,docker,export,folders,gpu,ip,raid,snmp,web,wifi]
Copied!

User & Permission

add user to group

1
sudo adduser foobar www-data
2
sudo usermod -a -G ftp tony
Copied!

password

1
echo user:pwd | chpasswd
Copied!

sudoers

1
sudo visudo
2
root ALL=(ALL) ALL # {terminals}=({users}) {commands}
3
%supergroup ALL=(ALL) NOPASSWD:ALL
Copied!

chown

1
chown -h myuser:mygroup mysymbolic
Copied!

Package Management

Redhat

Free RHEL: https://developers.redhat.com/articles/no-cost-rhel-faq/
1
subscription-manager register
2
subscription-manager attach --auto
3
subscription-manager repos --enable rhel-7-server-optional-rpms
4
subscription-manager repos --enable rhel-7-server-extras-rpms
5
yum install epel-release
6
rm -f /var/run/yum.pid <PID> && yum remove PackageKit
7
8
yum-config-manager --disable c7-media
9
yum --nogpgcheck localinstall xx.rpm
10
11
### EPEL
12
http://elrepo.org/tiki/tiki-index.php
13
14
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
15
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
16
yum install yum-plugin-fastestmirror
17
yum --enablerepo=elrepo-kernel install kernel-ml
Copied!

Ubuntu

Main - Canonical-supported free and open-source software. Universe - Community-maintained free and open-source software. Restricted - Proprietary drivers for devices. Multiverse - Software restricted by copyright or legal issues.
1
# https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
2
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
Copied!

Debian

→ experimental → unstable(Sid) → testing → stable Unstable - repository where new & untested packages are introduced. Testing - repository with packages from unstable, if no bug are found within 10 days.
main consists of DFSG-compliant packages, which do not rely on software outside this area to operate. These are the only packages considered part of the Debian distribution. contrib packages contain DFSG-compliant software, but have dependencies not in main (possibly packaged for Debian in non-free). non-free contains software that does not comply with the DFSG.
1
deb http://mirror.sjtu.edu.cn/debian/ bullseye main contrib non-free
Copied!

experimental

1
deb http://mirror.sjtu.edu.cn/debian/ experimental main contrib non-free
2
3
apt install -t experimental linux-image-amd64 # latest kernel
Copied!

dpkg

1
dpkg --get-selections # list installed
Copied!
To install .deb manually, visit linux/kernel page.

apt

1
apt-get install linux-base -t jessie-backports
2
apt-cache search linux-image | grep linux-image-4
3
apt install linux-image-4.10.0-9-generic linux-image-extra-4.10.0-9-generic
4
5
apt show linux-image-extra-4.10*
6
7
apt-get install --only-upgrade docker-engine
8
9
apt policy docker-ce | head -n 20
10
11
apt-get autoclean
12
apt list --installed
13
14
rm -r /var/lib/apt/lists/*
Copied!

ssh server

1
deb http://.../debian/ buster main contrib non-free
2
3
apt install openssh-server # not "openssl"
4
5
# fix: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
6
PubkeyAcceptedAlgorithms +ssh-rsa
Copied!

Grub

1
grub2-mkconfig -o /boot/grub2/grub.cfg
2
awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg
3
grub2-set-default 'CentOS Linux (4.9.0-rc8-amd64) 7 (Core)'
4
grub2-editenv list
Copied!

grub-customizer

1
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
2
sudo apt-get update
3
sudo apt-get install grub-customizer
Copied!

boot repair

https://sourceforge.net/p/boot-repair-cd/home/Home/ apt install linux-image-* # if vmlinuz & initrd.img missing

ubuntu

1
sudo add-apt-repository ppa:yannubuntu/boot-repair
2
sudo apt-get update
3
sudo apt-get install -y boot-repair && boot-repair
Copied!

Benchmark

http://www.brendangregg.com/Perf/linux_benchmarking_tools.png
1
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=32 run
2
3
wget http://www.numberworld.org/y-cruncher/y-cruncher%20v0.7.1.9466-static.tar.gz
4
tar zxvf y-cruncher\ v0.7.1.9466-static.tar.gz
Copied!

ssh redirect

1
ssh -L 9000:public.com:80 # visit local:9000 -> public.com:80
2
ssh -R 9000:localhost:3000 # visit remote:9000 -> local:3000, "GatewayPorts yes" in sshd_config
3
-nNT -L ... # port forwarding only, no shell
Copied!

web

wget

1
wget -O diff_name.zip http://...
Copied!

curl

1
curl -O http://...
2
curl -o diff_name.zip http://
3
4
curl -sSL $1
5
6
-f, --fail Fail silently (no output at all) on HTTP errors (H)
7
-s, --silent Silent mode (don't output anything)
8
-S, --show-error Show error. With -s, make curl show errors when they occur
9
-L, --location Follow redirects (H)
10
-o, --output FILE Write to FILE instead of stdout
11
-O, --remote-name Write output to a file named as the remote file
12
Copied!

files

String replace: http://unix.stackexchange.com/questions/112023/how-can-i-replace-a-string-in-a-files
1
apt-get install mlocate
2
updatedb
3
locate -S
4
lsof -p <PID>
5
6
ls --help | grep -E '[-][tr]\b'
7
-r, --reverse reverse order while sorting
8
extension -X, size -S, time -t, version -v
9
-t sort by modification time, newest first
10
11
mkdir -p /not/existing/folder
12
13
cat > file <<'EOL'
14
EOL
15
16
ncdu --exclude='/root/data/*' /
17
18
du -hcd 2 / | more
19
du -a / | sort -n -r | head -n 20
20
21
ls -1 $PWD | wc -l # count files
22
23
file /bin/ps
24
ldd /bin/ps
Copied!

find

1
find /home -iname tecmint.txt
2
find $1 -iname $2
3
# find . ! -readable / -writable / -executabl
4
# find . ! -perm -g=w
5
6
find -regextype posix-extended -regex ".*[.](py|sh)" -exec chmod +x {} \;
Copied!

grep

1
grep --color=auto -rn -P "${regex}" ${path}
2
# -r, --recursive like --directories=recurse
3
# -n, --line-number print line number with output lines
4
# -P, --perl-regexp PATTERN is a Perl regular expression
Copied!

compress/uncompress

1
gunzip file.gz
2
3
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file # Compress
4
5
tar -tvf my-data.tar.gz '*.py'
6
7
tar -zxvf toExtract.tar.gz
8
tar -xvf {tarball.tar} {special_file} -C /target/directory
9
10
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
11
tar -tvf archive.tar # List all files in archive.tar verbosely.
12
tar -xf archive.tar # Extract all files from archive.tar.
13
-t, --list list the contents of an archive
14
-j, --bzip2 filter the archive through bzip2
15
-c, --create create a new archive
16
-x, --extract, --get extract files from an archive
17
-z, --gzip, --gunzip, --ungzip filter the archive through gzip
18
-v, --verbose verbosely list files processed
19
-f, --file=ARCHIVE use archive file or device ARCHIVE
20
21
zip [options] zipfile files_list
22
-r recurse into directories
23
-x exclude the following names
24
-v verbose operation/print version info
25
26
-m move into zipfile (delete OS files) !!
27
-d delete entries in zipfile !!!
28
-u update: only changed or new files
29
30
xz --decompress file.xz # -dgrub # unxz
Copied!

rsync

1
rsync -aP -e "ssh -p $3" $1 [email protected]$2
2
3
rsync -aP /root/_bin [email protected]:/root
4
rsync -aP -e "ssh -p 10220" /local [email protected]:/dir --remove-source-files
5
-v, --verbose increase verbosity
6
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
7
--no-OPTION turn off an implied OPTION (e.g. --no-D)
8
-r, --recursive recurse into directories
9
-l, --links copy symlinks as symlinks
10
-p, --perms preserve permissions
11
-o, --owner preserve owner (super-user only)
12
-g, --group preserve group
13
-D same as --devices --specials
14
-t, --times preserve modification times
15
-S, --sparse handle sparse files efficiently
16
-e, --rsh=COMMAND specify the remote shell to use
17
--partial keep partially transferred files
18
--partial-dir=DIR put a partially transferred file into DIR
19
-z, --compress compress file data during the transfer
20
--progress show progress during transfer
21
-P same as --partial --progress
Copied!

history without line numbers

1
history | cut -c 8-
2
-a append history lines from this session to the history file ~/.bash_history
Copied!

hostname

1
hostnamectl set-hostname GZ2C8G
Copied!

font

1
apt-get install xfonts-base
Copied!

SELinux

1
getenforce
2
semanage port -a -t mongod_port_t -p tcp 27017
Copied!

Serial Console

https://wiki.openwrt.org/doc/hardware/port.serial
1
cat openwrt-lantiq-ram-u-boot.asc > /dev/ttyUSB0
2
screen /dev/ttyUSB0 115200
3
picocom -b 115200 /dev/ttyUSB0
Copied!

Dropbox

~/.dropbox-dist/dropboxd dropboxd will create a ~/Dropbox folder and start synchronizing it after this step! unlink: https://www.dropbox.com/account#security

Ubuntu snap

run without root

Proxy

1
vi /etc/environment
2
systemctl restart snapd
Copied!

JAVA_HOME

1
echo export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk" >> /etc/profile
Copied!

I18N & I10N

1
apt install -y locales-all
2
locale -a
3
dpkg-reconfigure locales
4
5
yum grouplist chinese-support
6
7
sudo apt-get install -y ttf-wqy-microhei #文泉驿-微米黑
8
sudo apt-get install -y ttf-wqy-zenhei #文泉驿-正黑
9
sudo apt-get install -y xfonts-wqy #文泉驿-点阵宋体
Copied!

Chrome

1
chromium --no-sandbox # start as root
Copied!

Proxy

1
export http_proxy=http://proxy_ip:1080
2
export https_proxy=http://proxy_ip:1080
3
4
sudo apt install -y proxychains
5
vi /etc/proxychains.conf
Copied!

AD

https://wiki.samba.org/index.php/Setting_up_Samba_as_an_NT4_PDC_(Quick_Start)

cache diagnostics

https://hoytech.com/vmtouch/
1
git clone https://github.com/hoytech/vmtouch.git
2
cd vmtouch && make && sudo make install
3
4
Discovering which files your OS is caching
5
Telling the OS to cache or evict certain files or regions of files
6
Locking files into memory so the OS won't evict them
7
Preserving virtual memory profile when failing over servers
8
Keeping a "hot-standby" file-server
9
Plotting filesystem cache usage over time
10
Maintaining "soft quotas" of cache usage
11
Speeding up batch/cron jobs
Copied!

WOL

1
ethtool enp1s0 | grep Wake-on
2
3
p (PHY activity)
4
u (unicast activity)
5
m (multicast activity)
6
b (broadcast activity)
7
g (magic packet activity) *
8
a (ARP activity)
9
d (disabled)
Copied!

Tools - Online

http://explainshell.com/

CPU

1
getconf LONG_BIT
Copied!

check_cpu_core_mapping

https://www.ibm.com/support/knowledgecenter/en/SSQPD3_2.6.0/com.ibm.wllm.doc/mappingcpustocore.html same physical/core ID =》 simultaneous multi threads (SMTs) / HT
1
cat /proc/cpuinfo | grep -P 'processor|physical id|core id|^#x27;
2
3
pip install walnut # pretty print
4
for c in sorted([ ( int(c['processor']), int(c['physical id']), int(c['core id']) ) for c in cpu.dict().values()]): print c
Copied!

USB Persistence

https://docs.kali.org/downloading/kali-linux-live-usb-persistence http://antix.mepis.org/index.php?title=Using_liveusb_with_persistence

kali

x86/M1/Live/VM/WSL/etc: https://www.kali.org/get-kali Docker: https://hub.docker.com/u/kalilinux/

tools

https://www.kali.org/tools/ screenshots/cheat sheet: https://www.comparitech.com/net-admin/kali-linux-cheat-sheet/#Kali_Linux_tools

Video

https://askubuntu.com/questions/28033/how-to-check-the-information-of-current-installed-video-drivers
1
dpkg -l amdgpu-pro
2
glxinfo | grep direct
3
GALLIUM_HUD=help glxgears
Copied!

OpenCL

installable client driver loader (ICD Loader) may expose multiple separate vendor installable client drivers (Vendor ICDs) for OpenCL.
1
sudo apt install ocl-icd-opencl-dev
Copied!

zFCP

device driver that supplements the Linux SCSI stack.
Could not load image

Diagram

Could not load image

diskless

https://help.ubuntu.com/community/DisklessUbuntuHowto
https://drbl.org/
1
docker run --network=host -d leejoneshane/drbl-server
Copied!
http://web.mst.edu/~vojtat/pegasus/administration.htm based on Scientific Linux 7 / CentOS 7 / Red Hat Enterprise Linux 7
Last modified 1mo ago